Skip to content

Commit f533c04

Browse files
committed
Linked to examples
1 parent 6494b7d commit f533c04

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

Part 4 - Concurrency/1. Scheduling and threading.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ r.run(); // Execute on main thread
2222
new Thread(r).start();
2323
new Thread(r).start();
2424
```
25-
Output
25+
[Output](/tests/java/itrx/chapter4/scheduling/SingleThreadedExample.java)
2626
```
2727
onNext(1) on 1
2828
Received 1 on 1
@@ -66,7 +66,7 @@ Observable.create(o -> {
6666

6767
System.out.println("Finished main: " + Thread.currentThread().getId());
6868
```
69-
Output
69+
[Output](/tests/java/itrx/chapter4/scheduling/SubscribeOnExample.java)
7070
```
7171
Main: 1
7272
Created on 1
@@ -77,7 +77,7 @@ Finished main: 1
7777

7878
We see here that, not only is everything executed on the same thread, it is actually sequential: `subscribe` does not unblock until it has completed subscribing to (and thus creating) the observable, which includes executing the body of `create`'s lambda parameter. The calls to `onNext` within that lambda execute the entire chain of operators, all the way to the `println`. Effectively, subscribing on a `create`d observable is blocking.
7979

80-
If you uncomment `.subscribeOn(Schedulers.newThread())`, the output now is
80+
If you uncomment `.subscribeOn(Schedulers.newThread())`, the [Output](/tests/java/itrx/chapter4/scheduling/SubscribeOnExample.java) now is
8181
```
8282
Main: 1
8383
Finished main: 1
@@ -100,7 +100,7 @@ Observable.interval(100, TimeUnit.MILLISECONDS)
100100

101101
System.out.println("Finished main: " + Thread.currentThread().getId());
102102
```
103-
Output
103+
[Output](/tests/java/itrx/chapter4/scheduling/SubscribeOnExample.java)
104104
```
105105
Main: 1
106106
Finished main: 1
@@ -124,7 +124,7 @@ Observable.create(o -> {
124124
.subscribe(i ->
125125
System.out.println("Received " + i + " on " + Thread.currentThread().getId()));
126126
```
127-
Output
127+
[Output](/tests/java/itrx/chapter4/scheduling/ObserveOnExample.java)
128128
```
129129
Created on 1
130130
Received 1 on 13
@@ -147,7 +147,7 @@ Observable.create(o -> {
147147
System.out.println("After " + i + " on " + Thread.currentThread().getId()))
148148
.subscribe();
149149
```
150-
Output
150+
[Output](/tests/java/itrx/chapter4/scheduling/ObserveOnExample.java)
151151
```
152152
Created on 1
153153
Before 1 on 1
@@ -183,7 +183,7 @@ source
183183
.unsubscribeOn(Schedulers.newThread())
184184
.subscribe(System.out::println);
185185
```
186-
Output
186+
[Output](/tests/java/itrx/chapter4/scheduling/UnsubscribeOnExample.java)
187187
```
188188
Subscribed on 1
189189
Producing on 1
@@ -256,7 +256,7 @@ worker.schedule(
256256
() -> System.out.println(System.currentTimeMillis()-start),
257257
5, TimeUnit.SECONDS);
258258
```
259-
Output
259+
[Output](/tests/java/itrx/chapter4/scheduling/SchedulerExample.java)
260260
```
261261
5033
262262
5035
@@ -282,7 +282,7 @@ worker.schedule(
282282
() -> System.out.println(System.currentTimeMillis()-start),
283283
5, TimeUnit.SECONDS);
284284
```
285-
Output
285+
[Output](/tests/java/itrx/chapter4/scheduling/SchedulerExample.java)
286286
```
287287
5032
288288
```
@@ -304,7 +304,7 @@ worker.schedule(() -> {
304304
Thread.sleep(500);
305305
worker.unsubscribe();
306306
```
307-
Output
307+
[Output](/tests/java/itrx/chapter4/scheduling/SchedulerExample.java)
308308
```
309309
Action interrupted
310310
```
@@ -326,7 +326,7 @@ worker.schedule(() -> {
326326
System.out.println("End");
327327
});
328328
```
329-
Output
329+
[Output](/tests/java/itrx/chapter4/scheduling/SchedulersExample.java)
330330
```
331331
Start
332332
Inner
@@ -346,7 +346,7 @@ worker.schedule(() -> {
346346
System.out.println("End");
347347
});
348348
```
349-
Output
349+
[Output](/tests/java/itrx/chapter4/scheduling/SchedulersExample.java)
350350
```
351351
Start
352352
End
@@ -378,7 +378,7 @@ worker.schedule(() -> {
378378
Thread.sleep(500);
379379
worker.schedule(() -> printThread("Again"));
380380
```
381-
Output
381+
[Output](/tests/java/itrx/chapter4/scheduling/SchedulersExample.java)
382382
```
383383
Main on 1
384384
Start on 11

0 commit comments

Comments
 (0)