To clarify the difference between Runnable and Thread, please run the following tests:
com.understand.concurrency.task0.RunnablesTest
com.understand.concurrency.task0.ThreadsTest
and send to reviewers detailed explanation of the output.
If we spawn multiple threads, then we can hardly control their execution oder, right ?
Please look at com.understand.concurrency.task1.SequenceBlocks#build
.
It spawns multiple threads and make their order sequential using join
method.
com.understand.concurrency.task1.SequenceBlocksTest#testBuild
checks that behaviour.
Please provide alternative solution without using 'java.lang.Thread#join()' method.
1 Please have a look at some examples:
-
com.understand.concurrency.task2.lock.SimpleLockTaskTest
- implementation usingsynchronized
keyword -
com.understand.concurrency.task2.lock.AtomicTaskTest
- implementation using classes fromjava.util.concurrent.atomic
package -
com.understand.concurrency.task2.lock.ReentrantLockTask
- implementation using classes fromjava.util.concurrent.locks
package
2 Please create your own thread-safe classes with set
and get
methods:
-
using
synchronized
-
using
java.util.concurrent.locks.ReentrantReadWriteLock
-
using
java.util.concurrent.locks.StampedLock
You are expected to have some unit tests.
3 Please see tests under com.understand.concurrency.task2.collections
package,
play around a bit and write why some tests are broken.
Tests for the all implementations should be under 'src.test.java.com.understand.concurrency.task2'. All tests should be executed into multi-concurrent mode (see, for instance, existing tests). Provide time execution measurement for the ALL tests. Collect and share time measurement results.
Provide implementation for producer / consumer problem using wait()
, notify()
/notifyAll()
.
For the implementation unit tests have to be developed.
Current implementation of com.understand.concurrency.task3.ExecutorsTask#task
cannot return result of the thread execution to the main thread.
Change the code to get the result of an asynchronous computation and print it out in the main thread.
Current com.understand.concurrency.task3_1.RemoteAPI
class has blocking implementation.
Unblocking solution should be implemented without using java.util.concurrent.CompletableFuture
.
1 Run com.understand.concurrency.task4.countdownlatch.Main
class - the video conference will be started when all the participants arrive.
Please implement the following:
- change the method com.understand.concurrency.task4.countdownlatch.VideoConference#arrive to return the participant's hello-message
- when the conference starts, then print out all participants' messages in the main thread
2 Go to the com.understand.concurrency.task4.cyclicbarrier
Documents from the printing line should be printed twice.
3 Go to the com.understand.concurrency.task4.atomicity
Documents printing should be organized with first-in first-out order manner.
For instance, in the current implementation we may see the following program trace:
pool-1-thread-1: is going to print document - PDF 1
pool-1-thread-2: is going to print document - PDF 2
pool-1-thread-1: has printed document - PDF 1
...
PDF1 and PDF2 threads are interleaved.
We want that the sequence would be like that:
pool-1-thread-1: is going to print document - PDF 1
pool-1-thread-1: has printed document - PDF 1
pool-1-thread-2: is going to print document - PDF 2
pool-1-thread-2: is going to print document - PDF 2
...
(threads for documents are not interleaved)
Please provide implementation.
4 Please change com.understand.concurrency.test4.SemaphoreTaskTest
according to its TODOs then investigate and provide report regarding threads name and their count.
For execution of request, user has to be logged in with 2 security APIs. Each of the APIs has some delay of authorization. In other words we do not know exactly which API will finished firstly.
Please improve a bit current implementation.
com.understand.concurrency.task5_1.Main#main
prints out the result of the async computation.
Please remove ThreadUtils.sleep
call and provide alternative working implementation without using java.util.concurrent.CompletableFuture#join
call.
Improve the current implementation of com.understand.concurrency.task6.ExecutorTask
to execute the task periodically
using java.util.concurrent.ScheduledExecutorService
.
Provide thread safe implementation for the Producer-Consumer pattern using java.util.concurrent.BlockingQueue
so we do not manually manage threads blocking.
For the implementation unit tests have to be developed (one of the tests should use the following settings: threadPoolSize = 500, invocationCount = 500).
Provide thread safe implementation for the producer consumer pattern with non-blocking mechanism.
There is one Producer (observable/publisher) and one or more Consumers (observable/subscribers). After producing data Producer notifies its Consumers.
For the implementation unit tests have to be developed (one of the tests should use the following settings: threadPoolSize = 500, invocationCount = 500).