Threads + sychnroznization

P

ppp

Hello, I have a little problem. I'm wondering how to interrupt my
thread work.
I have a several threads, they work on the same synchronized stock.
there is my pseudo-code of run method.

public void run() {

while (true) {
synchronized(Stock) {
if (Condition1)
// do something
else if (Condition2)
// do something else
else // default Condition
//i wish to end my Thread here
interrupt(); // thos method don't work
System.exit(1); // only this, but this is not good
solution...
}
try { sleep(new Random().nextInt(1000)); }
catch (InterruptedException e) {}
}
}


I wish to create 10-15 threads, and after default Condition stop.

maybe you have some good solutions of my problem?
 

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

Forum statistics

Threads
474,270
Messages
2,571,102
Members
48,773
Latest member
Kaybee

Latest Threads

Top