Results 1 to 4 of 4

Thread: Spring pauses when different process calls Thread.sleep

  1. #1
    Join Date
    Mar 2009
    Posts
    16

    Default Spring pauses when different process calls Thread.sleep

    Hi,

    I've encountered a big problem. I use Spring to inject resources to be loaded into commons configuration. Basically in my spring file I look for "classpath*:config.properties" and I get a Spring Resource[] object.

    This all happens in application A.

    I have a different project containing a unit test with no dependencies to application A. the unit test starts Application A using a sh file and running it via the Runtime.exec API.

    After starting the application A program from the unit test, I enter into a sleep for 15 seconds. I can see from spring logs that the loading of the resources (explicitly when calling resource.getUrl()) it hangs for almost the same amount as the sleep.

    With out the sleep, works fine.

    When I print the result of resource.getUrl() I see it finds the config files in different jars, which is Ok. could it be that someone else is holding a jar file, hence preventing from Spring to read the URL properly?

    Any suggestions from any one?

    Thanks.

  2. #2
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    So you start application A in a different process and communicate with it in your unit test, right?

    So maybe there is a problem in the inter-process communication. How do you handle InputStream and OutputStream of the startet process? You should have separate threads to handle these.
    Each process has a limited buffer. If that is full then it blocks, which might have happened in your case. So if your process generates output you must ensure that this gets processed somehow (you may ignore it, but you need to empty the stream).

    See Process#getOutputStream(), Process#getErrorStream(), Process#getInputStream().

    Regards,
    Andreas

  3. #3
    Join Date
    Mar 2009
    Posts
    16

    Default

    thanks, but this does not help.

    I have the lines of code:
    Code:
    			InputStream inputStream = process.getInputStream();
    			InputStream errorStream = process.getErrorStream();
    			
    			readAndPrintInputStream(inputStream);
    			readAndPrintInputStream(errorStream);
    Code:
    	private static void readAndPrintInputStream(InputStream inputStream) {
    		try {
    			int size = inputStream.available();
    			byte[] bytes = new byte[size];
    			inputStream.read(bytes);
    			System.out.println("input: " + new String(bytes));
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}

    nothing gets printed and I still see the pause.

    Any other ideas?

  4. #4
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    This is not exactly what I meant. The processing of the streams has to happen
    a) in a loop
    b) in a separate thread (one per stream). I suggest you use daemon-threads

    For a) see here for an example: http://www.exampledepot.com/egs/java...and.html?l=rel

    Regards,
    Andreas

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •