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

23
LINES

< > BotCompany Repo | #1035570 // LongPairCollector - concurrent collector for 2 longs with overridable complete() function

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

Libraryless. Click here for Pure Java version (94L/1K).

// assumes that each set function is called exactly once
// (but it doesn't matter which thread you call each of them from.)
sclass LongPairCollector > AtomicCounter {
  volatile long valueOfA;
  volatile long valueOfB;
  
  final LongConsumer a = l1 setA;
  final LongConsumer b = l1 setB;

  void setA(long a) { valueOfA = a; itemReceived(); }
  void setB(long b) { valueOfB = b; itemReceived(); }
  
  LongConsumer setA aka setterForA() { ret a; }
  LongConsumer setB aka setterForB() { ret b; }
  
  void itemReceived {
    if (incCounter() == 2)
      complete(valueOfA, valueOfB);
  }
  
  // override me
  void complete(long a, long b) {}
}

Author comment

Began life as a copy of #1035562

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1035570
Snippet name: LongPairCollector - concurrent collector for 2 longs with overridable complete() function
Eternal ID of this version: #1035570/12
Text MD5: 062cdc18c08e3cf9746be281b5723891
Transpilation MD5: 4a0107cfa16ac9f48077005870f06875
Author: stefan
Category: javax / parallelism
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-06-19 06:16:53
Source code size: 669 bytes / 23 lines
Pitched / IR pitched: No / No
Views / Downloads: 93 / 167
Version history: 11 change(s)
Referenced in: #1003674 - Standard Classes + Interfaces (LIVE continued in #1034167)
#1035581 - AtomicCounter
#1035582 - LongPairCollector (backup) - concurrent collector for 2 longs with overridable & swappable complete() function