1 package org.myoodb.core; 25 26 public class Timer extends Thread 27 { 28 private int m_timeout; 29 private int m_elapsed; 30 private boolean m_exitFlag; 31 private boolean m_hasExpired; 32 private java.io.ObjectInputStream m_input; 33 34 public Timer(java.io.ObjectInputStream input, int timeout) 35 { 36 m_elapsed = 0; 37 m_exitFlag = false; 38 m_hasExpired = false; 39 40 m_input = input; 41 m_timeout = timeout; 42 43 setDaemon(true); 44 } 45 46 private synchronized void expired() 47 { 48 m_hasExpired = true; 49 50 halt(); 51 52 try 53 { 54 m_input.close(); 55 } 56 catch (Exception e) 57 { 58 } 60 } 61 62 public boolean hasExpired() 63 { 64 return m_hasExpired; 65 } 66 67 public synchronized void halt() 68 { 69 m_exitFlag = true; 70 } 71 72 public synchronized void restart() 73 { 74 m_elapsed = 0; 75 } 76 77 public void run() 78 { 79 java.lang.Thread.currentThread().setName("Timer (" + m_input + ") Timeout Handler"); 80 81 while (m_exitFlag == false) 82 { 83 try 84 { 85 Thread.sleep(100); 86 } 87 catch (Exception e) 88 { 89 continue; 90 } 91 92 synchronized (this) 94 { 95 m_elapsed += 100; 96 97 if (m_elapsed > m_timeout) 98 { 99 expired(); 100 } 101 } 102 103 } 104 } 105 } 106 107 | Popular Tags |