• 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

Thread problem

 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
fallowing is the modified code from
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html




i need to call runexec(String cmd) method number of times in my programme but when i am calling first time the StreamGobbler.activeCount() is giving 35 and next time when ever i call its incrmenting 2 times but i am calling the runexec(String cmd) after it completes its execution


my question is why intially the activeCount() is showing more than 2 ?
and i want to use two threads that have been created i dont want to increase the number of threads every time i call the method

thanks in advance
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you running this application in some app server? That may account for the number of threads? Can't really answer your question from source code shown.

As for the stream gobbler it looks like it exits when it is done. Maybe it is because the program is still running? Does the output show that it is completed?

Henry
 
kamesh aru
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) yes i am running the application in an application server installed on as400
2) yes the dos command window that opens with java.exec command closes which i think implies that execution of programme complete as well i am getting the needed out put.

do we need to terminate the threads created ?as the thread count is increasing and taking the cpu as well the cpu is not coming down untill server is restarted .

thanks for the reply
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

do we need to terminate the threads created ?as the thread count is increasing and taking the cpu as well the cpu is not coming down untill server is restarted .



The thread should terminate when it is complete. It looks like from the source code that it should terminate as soon as the stream is closed. I would suggest that you debug it to confirm that the stream is actually closing.

In terms of resources, I would not worry about the threads. You will run out of file/network descriptors *way* before you have a thread problem. You need to confirm that the streams are closing.

Henry
 
kamesh aru
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in class StreamGobbler i closed streams with

br.close();
isr.close();

still i am getting the same error
thanks for the replies
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try calling enumerate on the thread group and getting a list of the active threads, and printing their names.
[ October 08, 2005: Message edited by: Mr. C Lamont Gilbert ]
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know if this has anything to do with the price of beans, but in one of my toy programs the StreamGobblers ran for some time after waitFor() came back. I'd add join() on the two gobblers right after waitFor() just to see what happens.
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Stan James:
I don't know if this has anything to do with the price of beans, but in one of my toy programs the StreamGobblers ran for some time after waitFor() came back. I'd add join() on the two gobblers right after waitFor() just to see what happens.



I actually encountered something similar in one of projects (wished it was a toy program though). The problem was caused by the fact that the program that I started, started another program. So even though the program that I started finished, meaning the waitFor() method returns, the streams were not closed because for some reason, I inherited the streams from the child process.

In the case that was Unix, I just started the process as a cron job, letting the cron server inherited the streams. And in the case of Windows, I had to live with it. Sooner of later the child process ended, and the threads terminated.

Henry
 
kamesh aru
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
fallowing is the out put i am getting while i am enumerating the activeCount() of the thread .
what is the main thread indicate is it the thread i started ?




thanks for the reply
 
kamesh aru
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can any one tell me what is thread main every time call the method its increamenting ?
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
next step is to name your threads


The naming increment is not entirely 'thread safe' but were just testing here.
 
kamesh aru
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the help
Thread[Gobbler 8,5,main]
Thread[Gobbler 9,5,main]

after each submit i am getting two threads old threads are not there in the out put but the main threads are increasing in number?
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic