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)

1  
static class MonoThread {
2  
  Thread t;
3  
  
4  
  boolean runIfNotRunning(final Runnable r) {
5  
    ret run(r);
6  
  }
7  
  
8  
  synchronized boolean run(final Runnable r) {
9  
    if (t == null) {
10  
      t = new Thread() {
11  
        public void run() {
12  
          try {
13  
            r.run();
14  
          } catch (Throwable e) {
15  
            e.printStackTrace();
16  
          } finally {
17  
            synchronized(MonoThread.this) {
18  
              t = null;
19  
            }
20  
          }
21  
        }
22  
      };
23  
      t.start();
24  
      return true;
25  
    } else
26  
      return false;
27  
  }
28  
}

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: 801 / 2100
Referenced in: [show references]