mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-13 10:45:51 +00:00
WalletFiles: use a ContextPropagatingThreadFactory instead of propagating the context explicitly.
Fixes bug found by devrandom
This commit is contained in:
parent
1352264e86
commit
a52c8669a4
@ -18,18 +18,15 @@
|
||||
package org.bitcoinj.wallet;
|
||||
|
||||
import org.bitcoinj.core.*;
|
||||
import org.bitcoinj.utils.Threading;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.bitcoinj.utils.*;
|
||||
import org.slf4j.*;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import javax.annotation.*;
|
||||
import java.io.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.*;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.*;
|
||||
|
||||
/**
|
||||
* A class that handles atomic and optionally delayed writing of the wallet file to disk. In future: backups too.
|
||||
@ -67,15 +64,8 @@ public class WalletFiles {
|
||||
}
|
||||
|
||||
public WalletFiles(final Wallet wallet, File file, long delay, TimeUnit delayTimeUnit) {
|
||||
final ThreadFactoryBuilder builder = new ThreadFactoryBuilder()
|
||||
.setDaemon(true)
|
||||
.setNameFormat("Wallet autosave thread")
|
||||
.setPriority(Thread.MIN_PRIORITY); // Avoid competing with the GUI thread.
|
||||
Thread.UncaughtExceptionHandler handler = Threading.uncaughtExceptionHandler;
|
||||
if (handler != null)
|
||||
builder.setUncaughtExceptionHandler(handler);
|
||||
// An executor that starts up threads when needed and shuts them down later.
|
||||
this.executor = new ScheduledThreadPoolExecutor(1, builder.build());
|
||||
this.executor = new ScheduledThreadPoolExecutor(1, new ContextPropagatingThreadFactory("Wallet autosave thread", Thread.MIN_PRIORITY));
|
||||
this.executor.setKeepAliveTime(5, TimeUnit.SECONDS);
|
||||
this.executor.allowCoreThreadTimeOut(true);
|
||||
this.executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
|
||||
@ -88,7 +78,6 @@ public class WalletFiles {
|
||||
|
||||
this.saver = new Callable<Void>() {
|
||||
@Override public Void call() throws Exception {
|
||||
Context.propagate(wallet.getContext());
|
||||
// Runs in an auto save thread.
|
||||
if (!savePending.getAndSet(false)) {
|
||||
// Some other scheduled request already beat us to it.
|
||||
|
Loading…
x
Reference in New Issue
Block a user