OnJava8-Examples/concurrent/Breakable.java
2016-12-25 12:36:49 -08:00

27 lines
689 B
Java

// concurrent/Breakable.java
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
import java.util.concurrent.*;
public class Breakable {
String id;
private int failcount;
public Breakable(String id, int failcount) {
this.id = id;
this.failcount = failcount;
}
@Override
public String toString() {
return "Breakable_" + id +
" [" + failcount + "]";
}
public static Breakable work(Breakable b) {
if(--b.failcount == 0)
throw new RuntimeException(
"Breakable_" + b.id + " failed");
System.out.println(b);
return b;
}
}