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

35
LINES

< > BotCompany Repo | #1035565 // FastCollabWorker - uses spin-locking or ms sleep

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (9670L/53K).

1  
srecord noeq FastCollabWorker(FastCollab collab, int workerIndex) extends Thread {
2  
  volatile gettable long errorCount;
3  
  volatile gettable long spinWaits;
4  
  volatile gettable long workCount;
5  
  volatile gettable Throwable lastError;
6  
  settable PingSource interruptor;
7  
  int sleepTime;
8  
  
9  
  run {
10  
    Runnable work;
11  
    var interruptor = this.interruptor;
12  
    sleepTime = collab.sleepTime;
13  
    
14  
    while ((work = collab.grabWork(workerIndex)) != collab.DONE) {
15  
      interruptor?.ping();
16  
      try {
17  
        if (work != null) {
18  
          ++workCount;
19  
          work.run();
20  
        } else
21  
          waitSome();
22  
      } catch e {
23  
        ++errorCount;
24  
        lastError = e;
25  
      }
26  
    }
27  
  }
28  
  
29  
  void waitSome ctex {
30  
    if (sleepTime == 0)
31  
      ++spinWaits;
32  
    else
33  
      sleep(sleepTime);
34  
  }
35  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): elmgxqgtpvxh, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035565
Snippet name: FastCollabWorker - uses spin-locking or ms sleep
Eternal ID of this version: #1035565/8
Text MD5: c13704fa386012993e966d71f658f677
Transpilation MD5: 84c925100f53966a9c61c4947d414b08
Author: stefan
Category: javax / parallelism
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-11-03 19:53:17
Source code size: 832 bytes / 35 lines
Pitched / IR pitched: No / No
Views / Downloads: 171 / 253
Version history: 7 change(s)
Referenced in: [show references]