Mercurial > repos > rliterman > csp2
comparison CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/opt/bbmap-39.01-1/current/kmer/OwnershipThread.java @ 68:5028fdace37b
planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author | jpayne |
---|---|
date | Tue, 18 Mar 2025 16:23:26 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
67:0e9998148a16 | 68:5028fdace37b |
---|---|
1 package kmer; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.concurrent.atomic.AtomicInteger; | |
5 | |
6 import shared.KillSwitch; | |
7 import shared.Shared; | |
8 import shared.Tools; | |
9 | |
10 public class OwnershipThread extends Thread { | |
11 | |
12 public static void clear(AbstractKmerTable[] tables){ | |
13 process(tables, CLEAR); | |
14 } | |
15 | |
16 public static void initialize(AbstractKmerTable[] tables){ | |
17 process(tables, INITIALIZE); | |
18 } | |
19 | |
20 private static void process(AbstractKmerTable[] tables, int mode){ | |
21 if(tables.length<2){ | |
22 if(mode==INITIALIZE){ | |
23 for(AbstractKmerTable akt : tables){akt.initializeOwnership();} | |
24 }else if(mode==CLEAR){ | |
25 for(AbstractKmerTable akt : tables){akt.clearOwnership();} | |
26 }else{ | |
27 KillSwitch.kill("Bad mode: "+mode); | |
28 } | |
29 return; | |
30 } | |
31 final int threads=Tools.min(Shared.threads(), tables.length); | |
32 final AtomicInteger next=new AtomicInteger(0); | |
33 ArrayList<OwnershipThread> alpt=new ArrayList<OwnershipThread>(threads); | |
34 for(int i=0; i<threads; i++){alpt.add(new OwnershipThread(tables, mode, next));} | |
35 for(OwnershipThread pt : alpt){pt.start();} | |
36 | |
37 for(OwnershipThread pt : alpt){ | |
38 while(pt.getState()!=Thread.State.TERMINATED){ | |
39 try { | |
40 pt.join(); | |
41 } catch (InterruptedException e) { | |
42 // TODO Auto-generated catch block | |
43 e.printStackTrace(); | |
44 } | |
45 } | |
46 } | |
47 } | |
48 | |
49 public OwnershipThread(AbstractKmerTable[] tables_, int mode_, AtomicInteger next_){ | |
50 tables=tables_; | |
51 mode=mode_; | |
52 next=next_; | |
53 } | |
54 | |
55 @Override | |
56 public void run(){ | |
57 for(int i=next.getAndIncrement(); i<tables.length; i=next.getAndIncrement()){ | |
58 if(mode==INITIALIZE){ | |
59 tables[i].initializeOwnership(); | |
60 }else if(mode==CLEAR){ | |
61 tables[i].clearOwnership(); | |
62 }else{ | |
63 KillSwitch.kill("Bad mode: "+mode); | |
64 } | |
65 } | |
66 } | |
67 | |
68 private final AbstractKmerTable[] tables; | |
69 private final AtomicInteger next; | |
70 private final int mode; | |
71 | |
72 public static final int INITIALIZE=0; | |
73 public static final int CLEAR=1; | |
74 | |
75 } |