First in weblogic console - Environment/Work Managers create one WorkManager
Then in code
workManager = (WorkManager) new InitialContext().lookup(<
Then add final List
final WorkItem workItem = workManager.schedule(new WorkClient());
workItems.add(workItem);
workManager.waitForAll(workItems, 1000s);
Then map response
for (final WorkItem workItem : workItems) {
if (workItem.getStatus() == WorkEvent.WORK_COMPLETED) {
workClient= ((WorkClient) workItem.getResult()).OURRESPONSEMETHODEXPOSED();
}
class WorkClient implements Work {
@Override
public void run() {
<
}
// have a return response method to return back
}
=> There are many ways using which we can generate Thread dump – Using Profiler, Kill -3 command, jstack tool etc. PREFER JSTACK
=> When we use volatile keyword with a variable, all the threads read it’s value directly from the memory and don’t cache it
=> Thread sleep() and yield() methods work on the currently executing thread. So there is no point in invoking these methods on some other threads that are in wait state. That’s why these methods are made static
=> When we create a Thread in java program, its state is New. Then we start the thread that change it’s state to Runnable
=> Java 5 introduced java.util.concurrent.Callable interface in concurrency package that is similar to Runnable interface but it can return any Object and able to throw Exception.
=> The Executor framework is a framework for standardizing invocation, scheduling, execution, and control of asynchronous tasks according to a set of execution policies.
=> classical way is using wait and notify method to communicate between Producer and Consumer thread and blocking each of them on individual condition like full queue and empty queue. With introduction of BlockingQueue Data Structure in Java 5 Its now much simpler because BlockingQueue provides this control implicitly by introducing blocking methods put() and take(). Now you don't require to use wait and notify to communicate between Producer and Consumer. BlockingQueue put() method will block if Queue is full in case of Bounded Queue and take() will block if Queue is empty. java.util.concurrent.BlockingQueue is a Queue that supports operations that wait for the queue to become non-empty when retrieving and removing an element, and wait for space to become available in the queue when adding an element.
Read more: https://javarevisited.blogspot.com/2012/02/producer-consumer-design-pattern-with.html#ixzz5M8v4OKzX
No comments:
Post a Comment