Skip to content

Commit c6b22e8

Browse files
committed
clean up
1 parent cc3408d commit c6b22e8

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

egg_StackOverflow_74464598/src/main/java/net/codetojoy/TaskRunner.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,36 @@ public class TaskRunner {
1515
this.doShutdown = doShutdown;
1616
}
1717

18-
private String taskGetNumItemsFromRequest() {
18+
private String taskGetNumItemsFromRequest() throws Exception {
1919
String result = "";
2020
try {
2121
result = new Worker().doWork(taskDelayInMillis, "taskGetNumItemsFromRequest", "numitems-5150");
2222
} catch (Exception ex) {
2323
System.err.println("TRACER TaskRunner num-items caught ex: " + ex);
24+
throw ex;
2425
}
2526
return result;
2627
}
2728

28-
private String taskGetPriceFromDB() {
29+
private String taskGetPriceFromDB() throws Exception {
2930
String result = "";
3031
try {
3132
result = new Worker().doWork(taskDelayInMillis, "taskGetPriceFromDB", "price-6160");
3233
} catch (Exception ex) {
3334
System.err.println("TRACER TaskRunner get-price caught ex: " + ex);
35+
throw ex;
3436
}
3537
return result;
3638
}
3739

3840
public String run() throws Exception {
39-
var result = "";
41+
var result = "error";
42+
4043
try (var scope = new StructuredTaskScope.ShutdownOnFailure()) {
4144
var numOrders = scope.fork(() -> taskGetNumItemsFromRequest());
4245
var price = scope.fork(() -> taskGetPriceFromDB());
4346

44-
try { Thread.sleep(500L); } catch (Exception ex) {}
47+
try { Thread.sleep(1000L); } catch (Exception ex) {}
4548

4649
if (doShutdown) {
4750
System.out.println("TRACER TaskRunner shutting down");
@@ -51,17 +54,11 @@ public String run() throws Exception {
5154
}
5255

5356
scope.join();
57+
scope.throwIfFailed();
5458

55-
try {
56-
scope.throwIfFailed();
59+
result = numOrders.resultNow() + " " + price.resultNow();
5760

58-
result = numOrders.resultNow() + " " + price.resultNow();
59-
} catch (Exception ex) {
60-
if (ex != null) {
61-
System.err.println("TRACER TaskRunner inner caught ex: " + ex.getClass());
62-
System.err.println("TRACER TaskRunner inner caught ex: " + ex.getMessage());
63-
}
64-
}
61+
System.out.println("TRACER TaskRunner post result");
6562
} catch (Exception ex) {
6663
if (ex != null) {
6764
System.err.println("TRACER TaskRunner caught ex: " + ex.getClass());

egg_StackOverflow_74464598/src/main/java/net/codetojoy/Worker.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
// note: I no longer own this domain
33
package net.codetojoy;
44

5-
import java.time.Duration;
6-
75
class Worker {
86
static final long THROW_EXCEPTION = -1L;
97

10-
void doSleep(long delayInMillis) throws InterruptedException {
11-
Thread.sleep(Duration.ofMillis(delayInMillis));
8+
void doSleep(long delayInMillis) throws Exception {
9+
Thread.sleep(java.time.Duration.ofMillis(delayInMillis));
1210
}
1311

1412
void logInfo(int index, String name) {

0 commit comments

Comments
 (0)