java - How to interrupt another thread from a monitor Thread -


I know that this is a sick advice, but even then I interfere in a thread that is hanging from one another Trying to check a method of giving thread that is keeping time.

What I'm doing: I'm starting the monitor thread before the suspicious network operation. This thread keeps track of the time when it started and if the time is greater than the threshold value, then it kills the thread which initially started it. To inform this new thread, the object of that thread is monitored, the object of the new thread is to kill the thread.

In short, it happens:

Now, the problem is that, it is not working for any reason, calling itself Binder. Land.

[Note: uppercase letters denote the names of the thread]

me Looks like there's something wrong code (unless I found your imagination not true) the code follows the expectation of the code (sorry for the terrible nested structure):

The output was:

  is going to be interrupted in C.B is interrupted. C is still alive ... is B so far? The false  

was the code:

  import java.util.concurrent.CountDownLatch; Import java.util.concurrent.atomic.AtomicReference; Public class scraps {public static zero main (string [] args) {thread A = new thread (override) {@ Override public war (run) {thread B = new thread () {@Override public void run () {last countdown link} = New countdown log (1); Last atomic reference & lt; Thread & gt; Pointer = new nuclear references & lt; Thread & gt; (); Thread C = new thread () {@ Override Public Wide Run (try {// B. should be latch.ait (); Thread.Sleep (2000); System.out.println ("Interrupted CB Pointer.get ();) between Thread.Sleep (2000); System.out.println ("C is still alive ... what is still alive?" + Pointer.get (). IsAlive ();} Grip (Interrupted e) E. {System.out.println ("C interrupted"); return;}}}; cc start (); latch.countDown (); // sure How do you do this, so it's going to be with: Pointer. Set (thread currentThread ()); Try {Thread.sle Ep (5000);} grip (interrupted ejection) {System.out.println ("inhibited in B"); return;} System.out.println ("b left");}}; //bb start ();}}; Beginning ();}}  

My (wild) guess will have intra-thread visibility in the above code, I am using atomic references to ensure visibility If you do not do this, then it is possible that the fields you pass to the reference (value of value) of thread B can be invisible for C. Then when C tries to disrupt this thread object, then it sees zero and interrupt results in the nullpointExtapin, and somehow you are not seeing it?


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -