Reputation: 1449
I have a thread running in my program When Mouse-down Event generates I want to put that thread in wait() and in Mouse-up I want to Notify that thread
But when I tried to do this It is giving me error like "Object not locked by Thread" so can anyone help me how to solve this..
Upvotes: 1
Views: 10779
Reputation: 11057
Just use Thread.sleep()
and then Thread.interrupt()
to wake it up.
something like this:
Thread t;
startThread() {
t = new Thread() {
public void run () {
doThings();
sleep(10000);
}
}
t.start();
}
interruptThread() {
if (t != null) t.interrupt();
}
Upvotes: 3
Reputation: 269
You can't stop the UI Thread (this is the Thread that called the event). This Thread is used to dispatch UI events and if you could make it wait() it'll render your UI unresponsive.
You'll have to create your own Thread.
Upvotes: 2
Reputation: 13062
as far as i know, calling wait() on a thread causes a crash... i dont know if there is a safe way to pause a thread (or at least an easy way)
Upvotes: 0