• Post Reply Bookmark Topic Watch Topic
  • New Topic

How many types of Threads are there generally?

 
shruthi Rao
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai friends,

I would like to know relating to Threads in generally as well as in JAVA i.e., How many Threads are available what are there uses how they try to perform over OS as well as to the users ? Please., helpme in this regard

Thank you
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The number of threads you can make before the JVM slows down or completely falls over depends on the JVM implementation, the OS, the hardware, other processes running, and so on. It's not really possible to say there is some upper limit.

I'm sure some applications go to pretty high numbers, but I've never had to make over 10 or 20, and I'd be worried about thrashing - where the JVM spends more time managing threads than doing any work - if they got into the hundreds.

Creating and destroying threads is rather expensive; if you find yourself making new ones at a high rate then thread pools (see Executors in Java 5) can greatly reduce overhead.

Anybody have any horror stories of hitting upper limits? Or success stories with hundreds of threads?
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was under the impression they were asking about threads the JVM automatically starts up. As far as I know, this is undefined and depends on the JVM implementation. The only thread that is available with a specific use you might be concerned with is the EDT thread in which all updates to the GUI should take place. If you're asking how many threads you can create, then that is dependent on a number of variants as Stan alluded to.

Personally, I've used Apache's XML-RPC server implementation which requires one thread per connection. Due to requirements it was necessary to implement my own thread pooling separate from that as well. I managed to hit it with ~100 connections resulting in hundreds of threads before it had problems, and this was running the clients and server together on the same, fairly old, Windows machine.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!