- Timestamp:
- 07/04/13 20:29:50 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/src/main/java/com/framsticks/util/dispatching/Monitor.java
r90 r96 2 2 3 3 import org.apache.log4j.Logger; 4 // import edu.umd.cs.findbugs.annotations.SuppressWarnings;5 4 import com.framsticks.util.dispatching.Dispatching; 5 import java.lang.Thread; 6 6 7 7 public class Monitor implements JoinableParent { … … 10 10 11 11 protected final Joinable joinable; 12 protected final Thread shutdownHook; 12 13 13 14 /** … … 16 17 public Monitor(Joinable joinable) { 17 18 this.joinable = joinable; 19 20 shutdownHook = new Thread(new Runnable() { 21 @Override 22 public void run() { 23 log.debug("running shutdown hook"); 24 Monitor.this.drop().join(); 25 } 26 }); 27 } 28 29 public Monitor use() { 30 Runtime.getRuntime().addShutdownHook(shutdownHook); 31 32 log.debug(this + " is using"); 33 Dispatching.use(joinable, this); 34 return this; 18 35 } 19 36 … … 34 51 } 35 52 36 public Monitor use() {37 log.debug(this + " is using");38 Dispatching.use(joinable, this);39 return this;40 }41 53 42 54 public Monitor drop() { … … 50 62 Dispatching.joinAbsolutely(joinable); 51 63 log.debug(this + " is joined"); 64 65 try { 66 Runtime.getRuntime().removeShutdownHook(shutdownHook); 67 } catch (IllegalStateException e) { 68 /** In case IllegalStateException is caught, it means that JVM is in finalization stage */ 69 } 70 52 71 return this; 53 72 } … … 67 86 } 68 87 88 @Override 89 public Monitor getMonitor() { 90 return this; 91 } 92 93 protected ExceptionHandler taskExceptionHandler; 94 95 /** 96 * @return the taskExceptionHandler 97 */ 98 public ExceptionHandler getTaskExceptionHandler() { 99 return taskExceptionHandler; 100 } 101 102 /** 103 * @param taskExceptionHandler the taskExceptionHandler to set 104 */ 105 public void setTaskExceptionHandler(ExceptionHandler taskExceptionHandler) { 106 this.taskExceptionHandler = taskExceptionHandler; 107 } 108 69 109 }
Note: See TracChangeset
for help on using the changeset viewer.