Second Thread Pool
An application that has a large number of database accesses or HTTP requests and a large number of concurrent users will have problems during heavy usage even if you make all the database accesses asynchronously. The solution to this problem is to create a second thread pool for all those database access threads. Some ES4 projects require a third thread pool. The general idea is to pull out any processes that are time consuming so that they do not use the ES4's own thread pool.
Managed Object
First create a class that extends BaseManagedObjectFactory that initializes a ThreadPoolExecutor and provides it in the acquireObject method.
Extension.xml
The new managed object must be added to the Extension.xml file of course. The managed object section goes above the event handlers and plugins.
Use in Plugins
Any plugin in the same extension can access the managed object.
Managed Object
First create a class that extends BaseManagedObjectFactory that initializes a ThreadPoolExecutor and provides it in the acquireObject method.
Extension.xml
The new managed object must be added to the Extension.xml file of course. The managed object section goes above the event handlers and plugins.
Use in Plugins
Any plugin in the same extension can access the managed object.
- Use getApi().acquireManagedObject to initialize a local variable for the ThreadPoolExecutor.
- Create a method that does the needed task.
- Create a Runnable that invokes that method. Any parameters will need to be final.
For more details, see the wiki's article on Threading in plugins.executor = (Executor) getApi().acquireManagedObject( "Executor", null );
protected final void execute( Runnable command ) {
if ( null == executor ) {
throw new IllegalStateException( "executor not initialized" );
}
executor.execute( command );
}
private void updatePlayerCurrency(final String playerName, final int newPoints) {
execute(new Runnable() {
@Override
public void run() {
asynchUpdatePlayerCurrency(playerName, newPoints);
}
});
}

Post a Comment
<< Home