Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make NewThreadScheduler create Daemon threads #631

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ private EventLoopScheduler() {

@Override
public Thread newThread(Runnable r) {
return new Thread(r, "RxNewThreadScheduler-" + count.incrementAndGet());
Thread t = new Thread(r, "RxNewThreadScheduler-" + count.incrementAndGet());
t.setDaemon(true);
return t;
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,8 @@ public void testParallelMerge() {

@Test
public void testNumberOfThreads() {
final ConcurrentHashMap<String, String> threads = new ConcurrentHashMap<String, String>();
Observable.merge(getStreams())
.toBlockingObservable().forEach(new Action1<String>() {

@Override
public void call(String o) {
System.out.println("o: " + o + " Thread: " + Thread.currentThread());
threads.put(Thread.currentThread().getName(), Thread.currentThread().getName());
}
});

// without injecting anything, the getStream() method uses Interval which runs on a default scheduler
assertEquals(Runtime.getRuntime().availableProcessors(), threads.keySet().size());

// clear
threads.clear();

// now we parallelMerge into 3 streams and observeOn for each
final ConcurrentHashMap<Long, Long> threads = new ConcurrentHashMap<Long, Long>();
// parallelMerge into 3 streams and observeOn for each
// we expect 3 threads in the output
OperationParallelMerge.parallelMerge(getStreams(), 3)
.flatMap(new Func1<Observable<String>, Observable<String>>() {
Expand All @@ -90,8 +74,8 @@ public Observable<String> call(Observable<String> o) {

@Override
public void call(String o) {
System.out.println("o: " + o + " Thread: " + Thread.currentThread());
threads.put(Thread.currentThread().getName(), Thread.currentThread().getName());
System.out.println("o: " + o + " Thread: " + Thread.currentThread().getId());
threads.put(Thread.currentThread().getId(), Thread.currentThread().getId());
}
});

Expand All @@ -100,7 +84,7 @@ public void call(String o) {

@Test
public void testNumberOfThreadsOnScheduledMerge() {
final ConcurrentHashMap<String, String> threads = new ConcurrentHashMap<String, String>();
final ConcurrentHashMap<Long, Long> threads = new ConcurrentHashMap<Long, Long>();

// now we parallelMerge into 3 streams and observeOn for each
// we expect 3 threads in the output
Expand All @@ -109,8 +93,8 @@ public void testNumberOfThreadsOnScheduledMerge() {

@Override
public void call(String o) {
System.out.println("o: " + o + " Thread: " + Thread.currentThread());
threads.put(Thread.currentThread().getName(), Thread.currentThread().getName());
System.out.println("o: " + o + " Thread: " + Thread.currentThread().getId());
threads.put(Thread.currentThread().getId(), Thread.currentThread().getId());
}
});

Expand Down