adeynack / more-executors Goto Github PK
View Code? Open in Web Editor NEWSpecialised executors for the JVM (mainly Java and Kotlin, but also Scala)
License: MIT License
Specialised executors for the JVM (mainly Java and Kotlin, but also Scala)
License: MIT License
Executors.newSingleThreadExecutor();
Because it creates a new thread. This proposition is an Executor that limits without creating any new thread. The thread pool already exist and we want to use it. In the end, the tasks are dispatched to an existing Executor (which does not have to be a pool, but is the typical use).
User submits a lambda receiving the actual state and returning both the value to return as a result of the operation and the new value of the state.
return stateGuard.mutateAndProvide(actual -> {
log.info("Adding user " + user.getName());
List<User> updatedUserList = new ArrayList<User>(actual.getUserList());
updatedUserList.add(user);
UserServiceState newState = new UserServiceState(updatedUserList);
List<String> userNames = new ArrayList(actual.getUserList().stream().map(u -> u.getName());
return new MutateAndProvideDecision(newState, userNames);
});
Ensures that state mutation is thread safe by holding the state value itself internally and making it available only when a task is dispatched to it.
This works better if the state is an immutable class using immutable collections, for total encapsulation.
Those are main ideas and not final interfaces.
User submits a lambda receiving the actual state and returning the new value of the state. The method itself returns a CompletionStage<Void>
to allow to caller to react upon the completion of the submitted task.
public CompletionStage<Void> addUser(User user) {
return stateGuard.mutate(actual -> {
log.info("Adding user " + user.getName());
List<User> updatedUserList = new ArrayList<User>(actual.getUserList());
updatedUserList.add(user);
UserServiceState newState = new UserServiceState(updatedUserList);
return newState;
});
}
User submits a lambda receiving the actual state and returning a value to pass down to the caller of the method.
public CompletionStage<List<String>> getUserNames() {
return stateGuard.provide((actual) -> {
new ArrayList(actual.getUserList().stream().map(u -> u.getName())
});
}
User submits a lambda receiving the actual state and returning both the value to return as a result of the operation and the new value of the state.
return stateGuard.mutateAndProvide(actual -> {
log.info("Adding user " + user.getName());
List<User> updatedUserList = new ArrayList<User>(actual.getUserList());
updatedUserList.add(user);
UserServiceState newState = new UserServiceState(updatedUserList);
List<String> userNames = new ArrayList(actual.getUserList().stream().map(u -> u.getName());
return new MutateAndProvideDecision(newState, userNames);
});
Executors.newFixedThreadPool
Because it creates new threads. This proposition is an Executor that limits without creating any new thread. The thread pool already exist and we want to use it. In the end, the tasks are dispatched to an existing Executor (which does not have to be a pool, but is the typical use).
https://travis-ci.org/Adeynack/more-executors/settings
/.travis.yaml
file (check instructions)It should be possible to create the current executor without providing a baseExecutor
. That should be using the default executor used for the CompletableFuture
.
Dummy (lacking a better one) implementation of such a base executor (in Kotlin):
val baseExecutor = Executor { CompletableFuture.runAsync(it) }
User submits a lambda receiving the actual state and returning a value to pass down to the caller of the method.
public CompletionStage<List<String>> getUserNames() {
return stateGuard.provide((actual) -> {
new ArrayList(actual.getUserList().stream().map(u -> u.getName())
});
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.