mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-19 21:25:38 +00:00
deps: Refactor dependencies (#3224)
* remove spring dep move junit, logging, mockito under dep mgmt * upgrade anti-corruption-layer deps * async method invocation * balking, bloc * bridge to bytecode * caching * callback - cqrs * component - health check * hexagonal - metadata mapping * rest of the patterns * remove checkstyle, take spotless into use
This commit is contained in:
@@ -43,13 +43,14 @@ import lombok.extern.slf4j.Slf4j;
|
||||
*
|
||||
* <p><i>APPLICABILITY</i> <br>
|
||||
* UNIX network subsystems - In operating systems network operations are carried out asynchronously
|
||||
* with help of hardware level interrupts.<br> CORBA - At the asynchronous layer one thread is
|
||||
* associated with each socket that is connected to the client. Thread blocks waiting for CORBA
|
||||
* requests from the client. On receiving request it is inserted in the queuing layer which is then
|
||||
* picked up by synchronous layer which processes the request and sends response back to the
|
||||
* client.<br> Android AsyncTask framework - Framework provides a way to execute long-running
|
||||
* blocking calls, such as downloading a file, in background threads so that the UI thread remains
|
||||
* free to respond to user inputs.<br>
|
||||
* with help of hardware level interrupts.<br>
|
||||
* CORBA - At the asynchronous layer one thread is associated with each socket that is connected to
|
||||
* the client. Thread blocks waiting for CORBA requests from the client. On receiving request it is
|
||||
* inserted in the queuing layer which is then picked up by synchronous layer which processes the
|
||||
* request and sends response back to the client.<br>
|
||||
* Android AsyncTask framework - Framework provides a way to execute long-running blocking calls,
|
||||
* such as downloading a file, in background threads so that the UI thread remains free to respond
|
||||
* to user inputs.<br>
|
||||
*
|
||||
* <p><i>IMPLEMENTATION</i> <br>
|
||||
* The main method creates an asynchronous service which does not block the main thread while the
|
||||
@@ -90,9 +91,7 @@ public class App {
|
||||
service.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* ArithmeticSumTask.
|
||||
*/
|
||||
/** ArithmeticSumTask. */
|
||||
static class ArithmeticSumTask implements AsyncTask<Long> {
|
||||
private final long numberOfElements;
|
||||
|
||||
|
||||
+21
-23
@@ -58,7 +58,6 @@ public class AsynchronousService {
|
||||
service = new ThreadPoolExecutor(10, 10, 10, TimeUnit.SECONDS, workQueue);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A non-blocking method which performs the task provided in background and returns immediately.
|
||||
*
|
||||
@@ -79,30 +78,29 @@ public class AsynchronousService {
|
||||
return;
|
||||
}
|
||||
|
||||
service.submit(new FutureTask<>(task) {
|
||||
@Override
|
||||
protected void done() {
|
||||
super.done();
|
||||
try {
|
||||
/*
|
||||
* called in context of background thread. There is other variant possible where result is
|
||||
* posted back and sits in the queue of caller thread which then picks it up for
|
||||
* processing. An example of such a system is Android OS, where the UI elements can only
|
||||
* be updated using UI thread. So result must be posted back in UI thread.
|
||||
*/
|
||||
task.onPostCall(get());
|
||||
} catch (InterruptedException e) {
|
||||
// should not occur
|
||||
} catch (ExecutionException e) {
|
||||
task.onError(e.getCause());
|
||||
}
|
||||
}
|
||||
});
|
||||
service.submit(
|
||||
new FutureTask<>(task) {
|
||||
@Override
|
||||
protected void done() {
|
||||
super.done();
|
||||
try {
|
||||
/*
|
||||
* called in context of background thread. There is other variant possible where result is
|
||||
* posted back and sits in the queue of caller thread which then picks it up for
|
||||
* processing. An example of such a system is Android OS, where the UI elements can only
|
||||
* be updated using UI thread. So result must be posted back in UI thread.
|
||||
*/
|
||||
task.onPostCall(get());
|
||||
} catch (InterruptedException e) {
|
||||
// should not occur
|
||||
} catch (ExecutionException e) {
|
||||
task.onError(e.getCause());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the pool of workers. This is a blocking call to wait for all tasks to be completed.
|
||||
*/
|
||||
/** Stops the pool of workers. This is a blocking call to wait for all tasks to be completed. */
|
||||
public void close() {
|
||||
service.shutdown();
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user