Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.concurrent.Semaphore;
- class latchestest1{
- public static void main(String[]args){
- Semaphore sem = new Semaphore(0);
- for(int j = 0; j<10; j++){
- new TA(sem, j).start();
- }
- System.out.println("Threads under starters orders");
- try{
- Thread.sleep(3000);
- }catch(InterruptedException e){}
- System.out.println("Starting threads now");
- sem.release(10);
- }
- }
- class TA extends Thread{
- Semaphore sem;
- int num;
- public TA (Semaphore s, int n){
- sem = s; num = n;
- }
- public void run(){
- //wait for signal to go
- try {
- sem.acquire();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- }
- System.out.println("Thread" +num+ "going");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement