1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-16 14:25:02 -05:00

* make sure core size is not limited to max thread pool size (seems to be a enforced limit now in JDK 8)

This commit is contained in:
Reinhard Pointner 2014-11-04 11:11:04 +00:00
parent fc70050ce3
commit 73c88dd365

View File

@ -1,7 +1,5 @@
package net.filebot.ui.sfv; package net.filebot.ui.sfv;
import static java.lang.Math.*; import static java.lang.Math.*;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
@ -17,7 +15,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import net.filebot.util.DefaultThreadFactory; import net.filebot.util.DefaultThreadFactory;
class ChecksumComputationService { class ChecksumComputationService {
public static final String TASK_COUNT_PROPERTY = "taskCount"; public static final String TASK_COUNT_PROPERTY = "taskCount";
@ -27,12 +24,10 @@ class ChecksumComputationService {
private final AtomicInteger completedTaskCount = new AtomicInteger(0); private final AtomicInteger completedTaskCount = new AtomicInteger(0);
private final AtomicInteger totalTaskCount = new AtomicInteger(0); private final AtomicInteger totalTaskCount = new AtomicInteger(0);
public ExecutorService newExecutor() { public ExecutorService newExecutor() {
return new ChecksumComputationExecutor(); return new ChecksumComputationExecutor();
} }
public void reset() { public void reset() {
synchronized (executors) { synchronized (executors) {
for (ExecutorService executor : executors) { for (ExecutorService executor : executors) {
@ -53,7 +48,6 @@ class ChecksumComputationService {
pcs.firePropertyChange(TASK_COUNT_PROPERTY, -1, getTaskCount()); pcs.firePropertyChange(TASK_COUNT_PROPERTY, -1, getTaskCount());
} }
/** /**
* Get the number of active executors that are associated with this {@link ChecksumComputationService}. * Get the number of active executors that are associated with this {@link ChecksumComputationService}.
* *
@ -66,22 +60,18 @@ class ChecksumComputationService {
} }
} }
public int getTaskCount() { public int getTaskCount() {
return totalTaskCount.get() - completedTaskCount.get(); return totalTaskCount.get() - completedTaskCount.get();
} }
public int getTotalTaskCount() { public int getTotalTaskCount() {
return totalTaskCount.get(); return totalTaskCount.get();
} }
public int getCompletedTaskCount() { public int getCompletedTaskCount() {
return completedTaskCount.get(); return completedTaskCount.get();
} }
public void purge() { public void purge() {
synchronized (executors) { synchronized (executors) {
for (ThreadPoolExecutor executor : executors) { for (ThreadPoolExecutor executor : executors) {
@ -90,11 +80,10 @@ class ChecksumComputationService {
} }
} }
private class ChecksumComputationExecutor extends ThreadPoolExecutor { private class ChecksumComputationExecutor extends ThreadPoolExecutor {
public ChecksumComputationExecutor() { public ChecksumComputationExecutor() {
super(1, 1, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new DefaultThreadFactory("ChecksumComputationPool", Thread.MIN_PRIORITY)); super(1, Runtime.getRuntime().availableProcessors(), 0L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new DefaultThreadFactory("ChecksumComputationPool", Thread.MIN_PRIORITY));
synchronized (executors) { synchronized (executors) {
if (executors.add(this) && executors.size() == 1) { if (executors.add(this) && executors.size() == 1) {
@ -107,7 +96,6 @@ class ChecksumComputationService {
prestartAllCoreThreads(); prestartAllCoreThreads();
} }
protected int getPreferredPoolSize() { protected int getPreferredPoolSize() {
// for a few files, use one thread // for a few files, use one thread
// for lots of files, use multiple threads // for lots of files, use multiple threads
@ -115,7 +103,6 @@ class ChecksumComputationService {
return max((int) log10(getQueue().size()), 1); return max((int) log10(getQueue().size()), 1);
} }
@Override @Override
public void execute(Runnable command) { public void execute(Runnable command) {
int preferredPoolSize = getPreferredPoolSize(); int preferredPoolSize = getPreferredPoolSize();
@ -133,7 +120,6 @@ class ChecksumComputationService {
pcs.firePropertyChange(TASK_COUNT_PROPERTY, getTaskCount() - 1, getTaskCount()); pcs.firePropertyChange(TASK_COUNT_PROPERTY, getTaskCount() - 1, getTaskCount());
} }
@Override @Override
public void purge() { public void purge() {
int delta = 0; int delta = 0;
@ -152,7 +138,6 @@ class ChecksumComputationService {
} }
} }
@Override @Override
protected void afterExecute(Runnable r, Throwable t) { protected void afterExecute(Runnable r, Throwable t) {
super.afterExecute(r, t); super.afterExecute(r, t);
@ -168,14 +153,12 @@ class ChecksumComputationService {
} }
} }
protected boolean isValid() { protected boolean isValid() {
synchronized (executors) { synchronized (executors) {
return executors.contains(this); return executors.contains(this);
} }
} }
@Override @Override
protected void terminated() { protected void terminated() {
synchronized (executors) { synchronized (executors) {
@ -186,12 +169,10 @@ class ChecksumComputationService {
private final PropertyChangeSupport pcs = new PropertyChangeSupport(this); private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
public void addPropertyChangeListener(PropertyChangeListener listener) { public void addPropertyChangeListener(PropertyChangeListener listener) {
pcs.addPropertyChangeListener(listener); pcs.addPropertyChangeListener(listener);
} }
public void removePropertyChangeListener(PropertyChangeListener listener) { public void removePropertyChangeListener(PropertyChangeListener listener) {
pcs.removePropertyChangeListener(listener); pcs.removePropertyChangeListener(listener);
} }