VIVO-870 Make the number of threads configurable.
Also, clean up the shutdown process and some comments.
This commit is contained in:
parent
8c3e06fc78
commit
56a640fe44
4 changed files with 35 additions and 11 deletions
|
@ -210,9 +210,7 @@ public class ApplicationImpl implements Application {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
getFileStorage().shutdown(this);
|
// Nothing to do.
|
||||||
getImageProcessor().shutdown(this);
|
|
||||||
getSearchEngine().shutdown(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
|
@ -108,8 +108,6 @@ public class ApplicationSetup implements ServletContextListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void contextDestroyed(ServletContextEvent sce) {
|
public void contextDestroyed(ServletContextEvent sce) {
|
||||||
if (app != null) {
|
// Nothing to do.
|
||||||
app.shutdown();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,7 +129,7 @@ public class FilterByRoleLevelPermission extends VitroFiltersImpl {
|
||||||
/**
|
/**
|
||||||
* It would be nice if every ObjectPropertyStatement held a real
|
* It would be nice if every ObjectPropertyStatement held a real
|
||||||
* ObjectProperty. If it doesn't, we do the next best thing, but it
|
* ObjectProperty. If it doesn't, we do the next best thing, but it
|
||||||
* won't recognize any applicaable Faux properties.
|
* won't recognize any applicable Faux properties.
|
||||||
*/
|
*/
|
||||||
private ObjectProperty getOrCreateProperty(ObjectPropertyStatement ops) {
|
private ObjectProperty getOrCreateProperty(ObjectPropertyStatement ops) {
|
||||||
if (ops.getProperty() != null) {
|
if (ops.getProperty() != null) {
|
||||||
|
|
|
@ -59,6 +59,8 @@ import edu.cornell.mannlib.vitro.webapp.searchindex.tasks.UpdateStatementsTask;
|
||||||
import edu.cornell.mannlib.vitro.webapp.searchindex.tasks.UpdateUrisTask;
|
import edu.cornell.mannlib.vitro.webapp.searchindex.tasks.UpdateUrisTask;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.configuration.ConfigurationBeanLoader;
|
import edu.cornell.mannlib.vitro.webapp.utils.configuration.ConfigurationBeanLoader;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.configuration.ConfigurationBeanLoaderException;
|
import edu.cornell.mannlib.vitro.webapp.utils.configuration.ConfigurationBeanLoaderException;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Property;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Validation;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.developer.DeveloperSettings;
|
import edu.cornell.mannlib.vitro.webapp.utils.developer.DeveloperSettings;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread;
|
import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread.WorkLevel;
|
import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread.WorkLevel;
|
||||||
|
@ -73,6 +75,9 @@ import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread.Work
|
||||||
* A thread pool is available so the tasks can create small units of work to be
|
* A thread pool is available so the tasks can create small units of work to be
|
||||||
* run in parallel. Each task should block until all of its work units are
|
* run in parallel. Each task should block until all of its work units are
|
||||||
* complete, to preserve the pattern of running one task at a time.
|
* complete, to preserve the pattern of running one task at a time.
|
||||||
|
*
|
||||||
|
* The number of threads in the thread pool is specified in the application
|
||||||
|
* setup file.
|
||||||
*/
|
*/
|
||||||
public class SearchIndexerImpl implements SearchIndexer {
|
public class SearchIndexerImpl implements SearchIndexer {
|
||||||
private static final Log log = LogFactory.getLog(SearchIndexerImpl.class);
|
private static final Log log = LogFactory.getLog(SearchIndexerImpl.class);
|
||||||
|
@ -80,7 +85,9 @@ public class SearchIndexerImpl implements SearchIndexer {
|
||||||
private final ListenerList listeners = new ListenerList();
|
private final ListenerList listeners = new ListenerList();
|
||||||
private final TaskQueue taskQueue = new TaskQueue();
|
private final TaskQueue taskQueue = new TaskQueue();
|
||||||
private final Scheduler scheduler = new Scheduler(taskQueue);
|
private final Scheduler scheduler = new Scheduler(taskQueue);
|
||||||
private final WorkerThreadPool pool = new WorkerThreadPool();
|
|
||||||
|
private Integer threadPoolSize;
|
||||||
|
private WorkerThreadPool pool;
|
||||||
|
|
||||||
private ServletContext ctx;
|
private ServletContext ctx;
|
||||||
private List<SearchIndexExcluder> excluders;
|
private List<SearchIndexExcluder> excluders;
|
||||||
|
@ -88,6 +95,27 @@ public class SearchIndexerImpl implements SearchIndexer {
|
||||||
private Set<IndexingUriFinder> uriFinders;
|
private Set<IndexingUriFinder> uriFinders;
|
||||||
private WebappDaoFactory wadf;
|
private WebappDaoFactory wadf;
|
||||||
|
|
||||||
|
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#threadPoolSize")
|
||||||
|
public void setThreadPoolSize(String size) {
|
||||||
|
if (threadPoolSize == null) {
|
||||||
|
threadPoolSize = Integer.parseInt(size);
|
||||||
|
} else {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Configuration includes multiple values for threadPoolSize: "
|
||||||
|
+ threadPoolSize + ", and " + size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Validation
|
||||||
|
public void validate() throws Exception {
|
||||||
|
if (threadPoolSize == null) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Configuration did not include a value for threadPoolSize.");
|
||||||
|
} else {
|
||||||
|
this.pool = new WorkerThreadPool(threadPoolSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startup(Application application, ComponentStartupStatus ss) {
|
public void startup(Application application, ComponentStartupStatus ss) {
|
||||||
try {
|
try {
|
||||||
|
@ -442,9 +470,9 @@ public class SearchIndexerImpl implements SearchIndexer {
|
||||||
public static class WorkerThreadPool {
|
public static class WorkerThreadPool {
|
||||||
private final ThreadPoolExecutor pool;
|
private final ThreadPoolExecutor pool;
|
||||||
|
|
||||||
public WorkerThreadPool() {
|
public WorkerThreadPool(int threadPoolSize) {
|
||||||
this.pool = new ThreadPoolExecutor(10, 10, 10, TimeUnit.SECONDS,
|
this.pool = new ThreadPoolExecutor(threadPoolSize, threadPoolSize,
|
||||||
new ArrayBlockingQueue<Runnable>(50),
|
10, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(50),
|
||||||
new VitroBackgroundThread.Factory(
|
new VitroBackgroundThread.Factory(
|
||||||
"SearchIndexer_ThreadPool"));
|
"SearchIndexer_ThreadPool"));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue