Announcement Announcement Module
No announcement yet.
Spring pauses when different process calls Thread.sleep Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring pauses when different process calls Thread.sleep


    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*" 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?


  • #2
    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().



    • #3
      thanks, but this does not help.

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

      nothing gets printed and I still see the pause.

      Any other ideas?


      • #4
        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: