The original question was this:
Wednesday, September 02, 2009 01:25:21 Subject: , how many threads will be created?.
I have written a java program,
Class 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
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 realize that (AWT or Swing applications, Timers, ExecutorSurvices, etc...).
1) if a class interacting with many classes and interaction with any remote resource,then single thread take care all of this
It could. Number of classes and method calls have nothing to do with threads. Remote resources have nothing directly to do with Threads, though some implementations may use Threads to make access more efficient.
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?
Can you tell us where you got that code from, and in what context? The code itself is a little problematic because there is no static variable in Thread called currentThread. There is a static method called currentThread() though. When asking questions it helps to be precise. If you could show us the code source or copy/paste the code exactly then we would be able to answer the question more precisely.
That code is not creating a Thread though. It appears to be using the value returned from currentThread() as a key to a map, in order to get some properties. The goal here is probably that the hash table is capable of storing different properties for different Threads (Thread-local values). If you had one object which
may be used by multiple Threads and you wanted different properties stored for each possible Thread then this is one solution. Personally, I would not use this myself. Instead I would use the
ThreadLocal object because the intent would be more clear.