Skip to content

Fixing the Thread pool centralization from which some mistakes have been done. #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -35,13 +35,7 @@
*/
public abstract class DbBuilderDynamicPart {

private static final ExecutorService executor;
private static final int threadCount;

static {
threadCount = ConfigurationHolder.getMaxThreadsCount();
executor = Executors.newFixedThreadPool(threadCount);
}
private ExecutorService executor;

private String SILVERPEAS_HOME = null;
private String SILVERPEAS_DATA = null;
@@ -56,6 +50,9 @@ public DbBuilderDynamicPart() {
* @return {@link ExecutorService}
*/
public ExecutorService getThreadExecutor() {
if (executor == null) {
executor = Executors.newFixedThreadPool(getThreadExecutorPoolCount());
}
return executor;
}

@@ -65,7 +62,7 @@ public ExecutorService getThreadExecutor() {
* @return the number of threads of the pool.
*/
public int getThreadExecutorPoolCount() {
return threadCount;
return ConfigurationHolder.getMaxThreadsCount();
}

public void setSILVERPEAS_HOME(String sh) throws Exception {
Original file line number Diff line number Diff line change
@@ -48,25 +48,22 @@
*/
public class WysiwygPurger extends DbBuilderDynamicPart {

private final ExecutorService executor;
private final SimpleDocumentService service;

/**
* The default constructor.
* A thread pool of 10 threads is handled.
*/
public WysiwygPurger() {
executor = Executors.newFixedThreadPool(10);
this.service = new SimpleDocumentService();
}

/**
* Hidden constructor used by tests.
* @param service
* @param fixedThreadPool
*
*/
WysiwygPurger(SimpleDocumentService service, int fixedThreadPool) {
executor = Executors.newFixedThreadPool(fixedThreadPool);
WysiwygPurger(SimpleDocumentService service) {
this.service = service;
}

@@ -82,7 +79,7 @@ public void purgeDocuments() throws Exception {
long totalNumberOfPurgedFiles = 0L;
long totalNumberOfRenamedFiles = 0L;
List<WysiwygDocumentPurger> mergers = buildWysiwygDocumentPurgers();
List<Future<WysiwygDocumentPurger.Result>> results = executor.invokeAll(mergers);
List<Future<WysiwygDocumentPurger.Result>> results = getThreadExecutor().invokeAll(mergers);
try {
for (Future<WysiwygDocumentPurger.Result> result : results) {
totalNumberOfPurgedFiles += result.get().getNbWysiwygContentPurged();
@@ -96,7 +93,7 @@ public void purgeDocuments() throws Exception {
ex);
throw ex;
} finally {
executor.shutdown();
getThreadExecutor().shutdown();
}
getConsole().printMessage("Nb of purged wysiwyg contents : " + totalNumberOfPurgedFiles);
getConsole()
17 changes: 12 additions & 5 deletions src/main/java/org/silverpeas/util/ConfigurationHolder.java
Original file line number Diff line number Diff line change
@@ -20,6 +20,10 @@
*/
package org.silverpeas.util;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.silverpeas.util.file.FileUtil;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -28,10 +32,6 @@
import java.net.URI;
import java.util.Properties;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.silverpeas.util.file.FileUtil;

/**
* This class holds all of the settings and parameters for the different applications used in the
* configuration of the Silverpeas portal.
@@ -168,10 +168,17 @@ public static String getJCRRepositoryConfiguration() throws IOException {
return confFile.getAbsolutePath();
}

/**
* Sets the maximum number of threads the executors of parallelized configuration tasks are
* permitted to allocate with their threads pool.
*/
public static void setMaxThreadsCount(int maxThreadCounts) {
System.setProperty(THREADS_KEY, String.valueOf(maxThreadCounts));
}

/**
* Gets the maximum number of threads the executors of parallelized configuration tasks are
* permitted to allocate with their threads pool.
*
* @return the number of threads to use in pools.
*/
public static int getMaxThreadsCount() {
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@
import org.silverpeas.migration.jcr.service.model.SimpleAttachmentBuilder;
import org.silverpeas.migration.jcr.service.model.SimpleDocument;
import org.silverpeas.test.jcr.JcrTest;
import org.silverpeas.util.ConfigurationHolder;
import org.silverpeas.util.Console;
import org.silverpeas.util.StringUtil;
import org.silverpeas.util.file.FileUtil;
@@ -237,7 +238,8 @@ public void run() throws Exception {
/*
The test
*/
WysiwygPurger purger = new WysiwygPurger(getSimpleDocumentService(), 1);
ConfigurationHolder.setMaxThreadsCount(1);
WysiwygPurger purger = new WysiwygPurger(getSimpleDocumentService());
purger.setConsole(new Console().setEchoAsDotEnabled(false));
purger.purgeDocuments();

@@ -472,7 +474,8 @@ public void run() throws Exception {
/*
The test
*/
WysiwygPurger purger = new WysiwygPurger(getSimpleDocumentService(), 1);
ConfigurationHolder.setMaxThreadsCount(1);
WysiwygPurger purger = new WysiwygPurger(getSimpleDocumentService());
purger.setConsole(new Console().setEchoAsDotEnabled(false));
purger.purgeDocuments();

@@ -569,7 +572,8 @@ public void run() throws Exception {
/*
The test
*/
WysiwygPurger purger = new WysiwygPurger(getSimpleDocumentService(), 1);
ConfigurationHolder.setMaxThreadsCount(1);
WysiwygPurger purger = new WysiwygPurger(getSimpleDocumentService());
purger.setConsole(new Console().setEchoAsDotEnabled(false));
purger.purgeDocuments();