Multithreaded Sleeping in a single Instance

J

James

Does anybody know of any issues I should be aware of doing the follow:
In a highly multithreaded J2SE application (1000+ threads), having an
object where 500+ threads share a single instance of a class that
contains a method with a Thread.sleep(n) call in. n will have a
different value for each thread and will be stored in a ThreadLocal
attribute. At any one time approximately half the threads will be
sleeping and half active.

The code needs to run on Windows XP pro, Solaris 10 and Red Hat
(version to be decided).

Any advice warnings of gotchas will be greatly appreciated.
 
C

Chris Uppal

James said:
Does anybody know of any issues I should be aware of doing the follow:
In a highly multithreaded J2SE application (1000+ threads),

Sounds like far too many threads to me. Threads are expensive. What are you
doing with them ?

-- chris
 
A

Alun Harford

James said:
Does anybody know of any issues I should be aware of doing the follow:
In a highly multithreaded J2SE application (1000+ threads), having an
object where 500+ threads share a single instance of a class that
contains a method with a Thread.sleep(n) call in. n will have a
different value for each thread and will be stored in a ThreadLocal
attribute. At any one time approximately half the threads will be
sleeping and half active.

The code needs to run on Windows XP pro, Solaris 10 and Red Hat
(version to be decided).

Any advice warnings of gotchas will be greatly appreciated.

Threads cost you resources. They need stacks, some memory in kernel mode,
and some memory on the heap. IIRC The default stack size is 256k in Windows
and Unix on x86.
You should avoid using that many threads. (Unless you're planning to run it
on a machine with 1000+ physical processors)

Alun Harford
 
R

Robert Klemme

Chris said:
Sounds like far too many threads to me. Threads are expensive. What are you
doing with them ?

Especially since half of them are sleeping. Sounds like there could be
a more efficient implementation pattern.

robert
 
S

search

better to use timer maybe -:)

Robert said:
Especially since half of them are sleeping. Sounds like there could be
a more efficient implementation pattern.

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top