Advertisement
Corosus

Untitled

Dec 24th, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.70 KB | None | 0 0
  1. java.nio.BufferUnderflowException
  2. 2013-12-24 18:05:32 [INFO] [STDERR]     at java.nio.Buffer.nextGetIndex(Unknown Source)
  3. 2013-12-24 18:05:32 [INFO] [STDERR]     at java.nio.HeapByteBuffer.getLong(Unknown Source)
  4. 2013-12-24 18:05:32 [INFO] [STDERR]     at deadmansswitch.DeadMansSwitch.checkForDeadMansSwitchReset(DeadMansSwitch.java:148)
  5.  
  6. which is long timeMilliseconds = bb.getLong();
  7.  
  8.  
  9.  
  10. public static boolean checkForDeadMansSwitchReset() {
  11.         try {
  12.             RandomAccessFile file = new RandomAccessFile("." + File.separator + "DeadMansSwitch.txt", "rw");
  13.             FileChannel fc = file.getChannel();
  14.             ByteBuffer bb = ByteBuffer.allocate(8);
  15.             int bytesRead = fc.read(bb);
  16.             long timeMilliseconds = bb.getLong();
  17.             fc.close();
  18.             System.out.println("read timeMilliseconds: " + timeMilliseconds);
  19.             if (timeMilliseconds != -1 && timeMilliseconds + restartThreshold > System.currentTimeMillis()) {
  20.                 System.out.println("we should restart!");
  21.                 return true;
  22.             }
  23.         } catch (Exception ex) {
  24.             ex.printStackTrace();
  25.         } finally {
  26.            
  27.         }
  28.         return false;
  29.     }
  30.    
  31.  
  32.    
  33.     public static void resetDeadMansSwitch(long timeVal) {
  34.         FileChannel fc = null;
  35.         try {
  36.             RandomAccessFile file = new RandomAccessFile("." + File.separator + "DeadMansSwitch.txt", "rw");
  37.             fc = file.getChannel();
  38.             ByteBuffer bb = ByteBuffer.allocate(8);
  39.             bb.clear();
  40.             bb.putLong(timeVal);
  41.             bb.flip();
  42.             while(bb.hasRemaining()) {
  43.                 fc.write(bb);
  44.             }
  45.             fc.close();
  46.             System.out.println("write timeMilliseconds: " + timeVal);
  47.         } catch (Exception ex) {
  48.             ex.printStackTrace();
  49.         } finally {
  50.            
  51.         }
  52.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement