mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-13 02:35:52 +00:00
Threading: prefer OOM to deadlock when the user thread is saturated, but keep the warning.
This commit is contained in:
parent
a9a7dd9e06
commit
80d4840199
@ -84,10 +84,10 @@ public class Threading {
|
|||||||
private static final Logger log = LoggerFactory.getLogger(UserThread.class);
|
private static final Logger log = LoggerFactory.getLogger(UserThread.class);
|
||||||
private LinkedBlockingQueue<Runnable> tasks;
|
private LinkedBlockingQueue<Runnable> tasks;
|
||||||
|
|
||||||
public UserThread(int tasksBound) {
|
public UserThread() {
|
||||||
super("bitcoinj user thread");
|
super("bitcoinj user thread");
|
||||||
setDaemon(true);
|
setDaemon(true);
|
||||||
tasks = new LinkedBlockingQueue<Runnable>(tasksBound);
|
tasks = new LinkedBlockingQueue<Runnable>();
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,13 +108,12 @@ public class Threading {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Runnable command) {
|
public void execute(Runnable command) {
|
||||||
// Will block if the event thread is saturated.
|
if (tasks.size() > 100) {
|
||||||
if (!tasks.offer(command)) {
|
log.warn("User thread saturated, memory exhaustion may occur.");
|
||||||
log.warn("User thread saturated, check for deadlocked or slow event handlers. Sample tasks:");
|
log.warn("Check for deadlocked or slow event handlers. Sample tasks:");
|
||||||
for (Object task : tasks.toArray()) log.warn(task.toString());
|
for (Object task : tasks.toArray()) log.warn(task.toString());
|
||||||
// Try again and wait this time.
|
|
||||||
Uninterruptibles.putUninterruptibly(tasks, command);
|
|
||||||
}
|
}
|
||||||
|
Uninterruptibles.putUninterruptibly(tasks, command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +123,7 @@ public class Threading {
|
|||||||
// from that point onwards.
|
// from that point onwards.
|
||||||
throwOnLockCycles();
|
throwOnLockCycles();
|
||||||
|
|
||||||
USER_THREAD = new UserThread(100); // 100 pending event listeners to avoid memory blowup.
|
USER_THREAD = new UserThread();
|
||||||
SAME_THREAD = new Executor() {
|
SAME_THREAD = new Executor() {
|
||||||
@Override
|
@Override
|
||||||
public void execute(@Nonnull Runnable runnable) {
|
public void execute(@Nonnull Runnable runnable) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user