Documente Academic
Documente Profesional
Documente Cultură
File APIs for Java Developers Manipulate DOC, XLS, PPT, PDF and many others from your application. http://aspose.com/file-tools
Java FAQ
Recent Topics
Register / Login
A special promo: Enter your blog post or vote on a blogger to be featured in an upcoming Journal
Author
jacob deiter Ranch Hand Joined: Apr 02, 2008 Posts: 576
For executing the above program, how many threads will be created?. I welcome your detailed explanation
Anirvan Majumdar Ranch Hand Joined: Feb 22, 2005 Posts: 261
In your case, only one main thread will be created - assuming you're not going to instantiate any 'thread' classes from Class A., and there's a main() defined in the class. Typically, when a Java application is executed, the JVM [java] process gets
1/4
www.coderanch.com/t/460814/threads/java/threads-created
6/13/13
loaded. This in turn spawns the main thread to execute your class. You might wonder if you instantiated another class from the first one, whether another thread will get spawned? The answer's no. Unless of course, that other class is a thread implementation itself.
jacob deiter Ranch Hand Joined: Apr 02, 2008 Posts: 576
In your case, only one main thread will be created - assuming you're not going to instantiate any 'thread' classes from C lass A., and there's a main() defined in the class. Typically, when a Java application is executed, the JVM [java] process gets loaded. This in turn spawns the main thread to execute your class. You might wonder if you instantiated another class from the first one, whether another thread will get spawned? The answer's no. Unless of course, that other class is a thread implementation itself.
1) if a class interacting with many classes and interaction with any remote resource,then single thread take care all of this 2) I read java code in that for getting enviroment data ,they are using hashhastble and thread as follow,.get Properties properties =some_hash_table.get(Thread.currentThread) could you please explain why? 3) as you said in your reply ,single process will b created for a application
Vijitha Kumara Bartender Joined: Mar 24, 2008 Posts: 3673
I like...
... 2) I read java code in that for getting enviroment data ,they are using hashhastble and thread as follow,.get Properties properties =some_hash_table.get(Thread.currentThread) could you please explain why?
Anirvan Majumdar
www.coderanch.com/t/460814/threads/java/threads-created
6/13/13
.... 2) I read java code in that for getting enviroment data ,they are using hashhastble and thread as follow,.get Properties properties =some_hash_table.get(Thread.currentThread) could you please explain why? ....
That looks like a strange bit of code, because I haven't typically seen anyone mapping values to a Thread instance. After all, every time the control comes to this statement, it will have a different thread instance [and hence, a different hash value for the instance]. My fair guess will be that in your application there's some sort of a thread pool being maintained. And each instance in that pool is associated with some unique set of properties. As mentioned before, if you can share the code snippet it might be helpful. I'd also suggest you investigate a bit more to understand whether or not your application has a multi-threaded implementation.
5
I like...
Wednesday, September 02, 2009 01:25:21 Subject: , how many threads will be created?. I have written a java program, C lass A{ //My code here }
For executing the above program, how many threads will be created?.
The answer to that is: It is impossible to say. The answer depends on what 'My Code' is. If you do nothing that generates new Threads then the answer would be at least one but usually 2, maybe more depending on JVM configurations. The two minimums would be 1) the main thread for running the application
www.coderanch.com/t/460814/threads/java/threads-created 3/4
6/13/13
2) a thread for garbage collection timing There are a lot of cases where more threads would be created but for which would be invisible to you, and other cases where threads will be made and you should rea
www.coderanch.com/t/460814/threads/java/threads-created
4/4