Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

28
LINES

< > BotCompany Repo | #1001434 // MonoThread class - replaced by SingleThread or ReliableSingleThread

JavaX fragment (include)

static class MonoThread {
  Thread t;
  
  boolean runIfNotRunning(final Runnable r) {
    ret run(r);
  }
  
  synchronized boolean run(final Runnable r) {
    if (t == null) {
      t = new Thread() {
        public void run() {
          try {
            r.run();
          } catch (Throwable e) {
            e.printStackTrace();
          } finally {
            synchronized(MonoThread.this) {
              t = null;
            }
          }
        }
      };
      t.start();
      return true;
    } else
      return false;
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1001434
Snippet name: MonoThread class - replaced by SingleThread or ReliableSingleThread
Eternal ID of this version: #1001434/1
Text MD5: 8709e1417fdeb4905603a235ef9c25b2
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-12-28 21:02:57
Source code size: 569 bytes / 28 lines
Pitched / IR pitched: No / No
Views / Downloads: 798 / 2095
Referenced in: [show references]