multithreading - Pausing/unpausing a thread upon keypress in Java -
i'm hoping can me this. i've been searching week answer issue, no avail.
i have custom thread class implements runnable
, i'd pause upon key press. based on research, i've learned best way go using wait()
, notify()
, triggered key that's using key binding.
my question is, how can work? can't seem set key binding without going wrong, , how might implement wait()
, notify()
without running deadlock beyond me.
wait , notify meant used synchronization. seems me wanted use methods thread.suspend(), thread.stop() , thread.resume(), have been deprecated risk of problems lock cause.
the solution use helper variable thread check periodically see if should running, otherwise, yield(or sleep)
why not use suspend, stop or resume: http://docs.oracle.com/javase/6/docs/technotes/guides/concurrency/threadprimitivedeprecation.html
simple solutions: how pause , resume thread in java thread
Comments
Post a Comment