• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Process waits forever when using Stringbuffer with more than 2000 strings

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am using ProcessBuilder to invoke an external command which will provide me the output. And I'm supplying input through String Buffer. My program works fine for 2934 strings within StringBuffer. However, the moment my stringbuffer size goes beyond 2934, the program hangs & waits forever.

Below is my code.




Can anyone tell me what could be the issue? Is there any limit in String Buffer? If so, how to resolve it?

PS: I also tried specifying large capacity such as 99999 in constructor of String buffer but still no luck....

Thanks!
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you really writing of .append("string"); 2000 times? That might take the method size over the maximum allowed.

And this is too difficult a question for beginners. Moving.
 
Campbell Ritchie
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And what are you doing with the input and error streams from the Process? You know you have to "drain" them both, otherwise the Process may suffer deadlock.
 
Vivek Jain
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes....I'm in fact giving input of 9000 strings within String Buffer.

Using , I'm actually capturing the output of the external utility which I am calling using ProcessBuilder.

Can you please help?

It looks like the buffer cannot accommodate much data. I just tried replacing String Buffer with Array List but the problem stays the same. So, it could be related to the output stream being not able to handle much data.

ok....I just noticed that the program works fine for small chunk of strings say 500 strings. However, if I use more than this limit, it just hangs at line process.waitFor().

What could be the resolution?

Thanks!

 
Vivek Jain
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
After doing more analysis, I noticed that the process is hanging because the I/O buffer is full...And it should be released by reading it.

If I try the below code, it works fine...But again it also has the limitation of processing around 8000 strings.....and thats not the right approach since I'm reading it before even knowing whether the process has finished it or not....So is there any other better soln???



thanks!
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Someone here hasn't read the Javaworld article "When Runtime.exec won't"
 
Vivek Jain
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rob,
I've read the article at Javaworld. Appreciate if you can tell me the solution for my case?

Thanks!
 
Rob Spoor
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try reading the error stream as well, in a different thread.
 
Vivek Jain
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rob,
Still no luck....Tried reading both error & input streams before waiFor....it hangs....When I do the Ctrl-C, it gives below error:



And if I look at the line number 2990 from above error, it seems like the issue is somewhere else.....Basically, when I'm throwing the string as an input to this external utility, it is hanging there itself....



Code hangs at Line 2990 which is writer.write(lst);

Can you please help fixing the issue?

Appreciate your help!!!
reply
    Bookmark Topic Watch Topic
  • New Topic