Java Threads and the Concurrency Utilities by Jeff Friesen

Java Threads and the Concurrency Utilities by Jeff Friesen

Author:Jeff Friesen
Language: eng
Format: mobi, epub, pdf
ISBN: 9781484216996
Publisher: Apress


class EmptyingLoop implements Runnable

{

@Override

public void run()

{

DataBuffer currentBuffer = initialFullBuffer;

try

{

while (true)

{

takeFromBuffer(currentBuffer);

if (currentBuffer.isEmpty())

{

System.out.println("emptying thread wants to " +

"exchange");

currentBuffer = exchanger.exchange(currentBuffer);

System.out.println("emptying thread receives " +

"exchange");

}

}

}

catch (InterruptedException ie)

{

System.out.println("emptying thread interrupted");

}

}

void takeFromBuffer(DataBuffer buffer)

{

System.out.println("taking: " + buffer.remove());

}

}

new Thread(new EmptyingLoop()).start();

new Thread(new FillingLoop()).start();

}

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.