17
17
import java .util .List ;
18
18
import java .util .Map ;
19
19
import java .util .Vector ;
20
+ import java .util .concurrent .BlockingQueue ;
21
+ import java .util .concurrent .LinkedBlockingQueue ;
22
+ import java .util .concurrent .TimeUnit ;
20
23
21
24
import net .sf .j2s .ajax .SimpleSerializable ;
22
25
import net .sf .j2s .annotation .J2SIgnore ;
@@ -50,6 +53,9 @@ public static interface IPipeClosing {
50
53
51
54
static Map <String , SimplePipeRunnable > pipes ;
52
55
56
+ @ J2SIgnore
57
+ private static BlockingQueue <SimplePipeRunnable > toBeDestroyedPipes = new LinkedBlockingQueue <SimplePipeRunnable >();
58
+
53
59
@ J2SIgnore
54
60
private SimplePipeHelper () {
55
61
//
@@ -417,9 +423,41 @@ private static void monitoringAllPipes() {
417
423
}
418
424
System .err .println ("Pipe sessions are null or empty! Pipe session monitor exited!" );
419
425
}
420
-
426
+
427
+ @ J2SIgnore
428
+ private static void killingPipes () {
429
+ while (true ) {
430
+ SimplePipeRunnable pipe = null ;
431
+ try {
432
+ pipe = toBeDestroyedPipes .poll (30 , TimeUnit .SECONDS );
433
+ } catch (InterruptedException e1 ) {
434
+ e1 .printStackTrace ();
435
+ }
436
+ if (pipe != null ) {
437
+ //System.out.println("Killing pipe " + pipe + " :// " + System.currentTimeMillis());
438
+ try {
439
+ if (pipe .closer != null ) {
440
+ pipe .closer .helpClosing (pipe ); // will call pipe.pipeDestroy()
441
+ } else {
442
+ pipe .pipeClosed (); // will call pipe.pipeDestroy()
443
+ }
444
+ } catch (Throwable e ) {
445
+ e .printStackTrace ();
446
+ }
447
+ //System.out.println("Killed pipe " + pipe + " :// " + System.currentTimeMillis());
448
+ } else {
449
+ //System.out.println("?? Empty loop?");
450
+ }
451
+ }
452
+ }
453
+
421
454
@ J2SIgnore
422
455
static void asyncDestroyPipe (final SimplePipeRunnable pipe ) {
456
+ //System.out.println("To destroy pipe " + pipe);
457
+ if (!toBeDestroyedPipes .contains (pipe )) {
458
+ toBeDestroyedPipes .offer (pipe );
459
+ }
460
+ /*
423
461
(new Thread("Destroy Pipe Thread") {
424
462
@Override
425
463
public void run() {
@@ -434,6 +472,7 @@ public void run() {
434
472
}
435
473
}
436
474
}).start();
475
+ // */
437
476
}
438
477
439
478
@ J2SIgnore
@@ -451,6 +490,13 @@ public void run() {
451
490
};
452
491
thread .setDaemon (true );
453
492
thread .start ();
493
+ Thread killerThread = new Thread ("Managed Pipe Session Killer" ) {
494
+ public void run () {
495
+ killingPipes ();
496
+ }
497
+ };
498
+ killerThread .setDaemon (true );
499
+ killerThread .start ();
454
500
}
455
501
456
502
}
0 commit comments