2016-12-25 12:36:49 -08:00
|
|
|
// concurrent/Breakable.java
|
2020-10-07 13:35:40 -06:00
|
|
|
// (c)2020 MindView LLC: see Copyright.txt
|
2016-12-25 12:36:49 -08:00
|
|
|
// 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) {
|
2017-01-06 15:03:36 -08:00
|
|
|
if(--b.failcount == 0) {
|
|
|
|
System.out.println(
|
|
|
|
"Throwing Exception for " + b.id + "");
|
2016-12-25 12:36:49 -08:00
|
|
|
throw new RuntimeException(
|
|
|
|
"Breakable_" + b.id + " failed");
|
2017-01-06 15:03:36 -08:00
|
|
|
}
|
2016-12-25 12:36:49 -08:00
|
|
|
System.out.println(b);
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
}
|