本文整理汇总了Java中org.bitcoinj.utils.Threading.uncaughtExceptionHandler方法的典型用法代码示例。如果您正苦于以下问题:Java Threading.uncaughtExceptionHandler方法的具体用法?Java Threading.uncaughtExceptionHandler怎么用?Java Threading.uncaughtExceptionHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bitcoinj.utils.Threading
的用法示例。
在下文中一共展示了Threading.uncaughtExceptionHandler方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exceptionCaught
import org.bitcoinj.utils.Threading; //导入方法依赖的package包/类
/** Catch any exceptions, logging them and then closing the channel. */
private void exceptionCaught(Exception e) {
PeerAddress addr = getAddress();
String s = addr == null ? "?" : addr.toString();
if (e instanceof ConnectException || e instanceof IOException) {
// Short message for network errors
log.info(s + " - " + e.getMessage());
} else {
log.warn(s + " - ", e);
Thread.UncaughtExceptionHandler handler = Threading.uncaughtExceptionHandler;
if (handler != null)
handler.uncaughtException(Thread.currentThread(), e);
}
close();
}
示例2: saveNow
import org.bitcoinj.utils.Threading; //导入方法依赖的package包/类
/** If auto saving is enabled, do an immediate sync write to disk ignoring any delays. */
public void saveNow() {
lock.lock();
try {
WalletFiles files = vFileManager;
if (files != null) {
try {
files.saveNow(); // This calls back into saveToFile().
} catch (IOException e) {
// Can't really do much at this point, just let the API user know.
log.error("Failed to save wallet to disk!", e);
Thread.UncaughtExceptionHandler handler = Threading.uncaughtExceptionHandler;
if (handler != null)
handler.uncaughtException(Thread.currentThread(), e);
}
}
} finally {
lock.unlock();
}
}
示例3: WalletFiles
import org.bitcoinj.utils.Threading; //导入方法依赖的package包/类
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.setKeepAliveTime(5, TimeUnit.SECONDS);
this.executor.allowCoreThreadTimeOut(true);
this.executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
this.wallet = checkNotNull(wallet, "Cannot save a null wallet");
// File must only be accessed from the auto-save executor from now on, to avoid simultaneous access.
this.file = checkNotNull(file, "Cannot save to a null file");
this.savePending = new AtomicBoolean();
this.delay = delay;
this.delayTimeUnit = checkNotNull(delayTimeUnit, "Cannot use a null delay time unit");
this.saver = new Callable<Void>() {
@Override public Void call() throws Exception {
// Runs in an auto save thread.
if (!savePending.getAndSet(false)) {
// Some other scheduled request already beat us to it.
return null;
}
log.info("Background saving wallet");
saveNowInternal();
return null;
}
};
}
示例4: WalletFiles
import org.bitcoinj.utils.Threading; //导入方法依赖的package包/类
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.setKeepAliveTime(5, TimeUnit.SECONDS);
this.executor.allowCoreThreadTimeOut(true);
this.executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
this.wallet = checkNotNull(wallet);
// File must only be accessed from the auto-save executor from now on, to avoid simultaneous access.
this.file = checkNotNull(file);
this.savePending = new AtomicBoolean();
this.delay = delay;
this.delayTimeUnit = checkNotNull(delayTimeUnit);
this.saver = new Callable<Void>() {
@Override public Void call() throws Exception {
// Runs in an auto save thread.
if (!savePending.getAndSet(false)) {
// Some other scheduled request already beat us to it.
return null;
}
log.info("Background saving wallet, last seen block is {}/{}", wallet.getLastBlockSeenHeight(), wallet.getLastBlockSeenHash());
saveNowInternal();
return null;
}
};
}
示例5: saveNow
import org.bitcoinj.utils.Threading; //导入方法依赖的package包/类
/** If auto saving is enabled, do an immediate sync write to disk ignoring any delays. */
protected void saveNow() {
WalletFiles files = vFileManager;
if (files != null) {
try {
files.saveNow(); // This calls back into saveToFile().
} catch (IOException e) {
// Can't really do much at this point, just let the API user know.
log.error("Failed to save wallet to disk!", e);
Thread.UncaughtExceptionHandler handler = Threading.uncaughtExceptionHandler;
if (handler != null)
handler.uncaughtException(Thread.currentThread(), e);
}
}
}
示例6: onCreate
import org.bitcoinj.utils.Threading; //导入方法依赖的package包/类
@Override
public void onCreate() {
new LinuxSecureRandom(); // init proper random number generator
initLogging();
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().permitDiskReads()
.permitDiskWrites().penaltyLog().build());
Threading.throwOnLockCycles();
org.bitcoinj.core.Context.enableStrictMode();
org.bitcoinj.core.Context.propagate(Constants.CONTEXT);
log.info("=== starting app using configuration: {}, {}", Constants.TEST ? "test" : "prod",
Constants.NETWORK_PARAMETERS.getId());
super.onCreate();
packageInfo = packageInfoFromContext(this);
CrashReporter.init(getCacheDir());
Threading.uncaughtExceptionHandler = new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(final Thread thread, final Throwable throwable) {
log.info("bitcoinj uncaught exception", throwable);
CrashReporter.saveBackgroundTrace(throwable, packageInfo);
}
};
initMnemonicCode();
config = new Configuration(PreferenceManager.getDefaultSharedPreferences(this), getResources());
activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
blockchainServiceIntent = new Intent(this, BlockchainServiceImpl.class);
blockchainServiceCancelCoinsReceivedIntent = new Intent(BlockchainService.ACTION_CANCEL_COINS_RECEIVED, null,
this, BlockchainServiceImpl.class);
blockchainServiceResetBlockchainIntent = new Intent(BlockchainService.ACTION_RESET_BLOCKCHAIN, null, this,
BlockchainServiceImpl.class);
walletFile = getFileStreamPath(Constants.Files.WALLET_FILENAME_PROTOBUF);
loadWalletFromProtobuf();
if (config.versionCodeCrossed(packageInfo.versionCode, VERSION_CODE_SHOW_BACKUP_REMINDER)
&& !wallet.getImportedKeys().isEmpty()) {
log.info("showing backup reminder once, because of imported keys being present");
config.armBackupReminder();
}
config.updateLastVersionCode(packageInfo.versionCode);
afterLoadWallet();
cleanupFiles();
initNotificationManager();
}
示例7: onCreate
import org.bitcoinj.utils.Threading; //导入方法依赖的package包/类
@Override
public void onCreate()
{
new LinuxSecureRandom(); // init proper random number generator
initLogging();
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().permitDiskReads().permitDiskWrites().penaltyLog().build());
Threading.throwOnLockCycles();
log.info("=== starting app using configuration: {}, {}", Constants.TEST ? "test" : "prod", Constants.NETWORK_PARAMETERS.getId());
super.onCreate();
packageInfo = packageInfoFromContext(this);
CrashReporter.init(getCacheDir());
Threading.uncaughtExceptionHandler = new Thread.UncaughtExceptionHandler()
{
@Override
public void uncaughtException(final Thread thread, final Throwable throwable)
{
log.info("bitcoinj uncaught exception", throwable);
CrashReporter.saveBackgroundTrace(throwable, packageInfo);
}
};
initMnemonicCode();
config = new Configuration(PreferenceManager.getDefaultSharedPreferences(this), getResources());
activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
blockchainServiceIntent = new Intent(this, BlockchainServiceImpl.class);
blockchainServiceCancelCoinsReceivedIntent = new Intent(BlockchainService.ACTION_CANCEL_COINS_RECEIVED, null, this,
BlockchainServiceImpl.class);
blockchainServiceResetBlockchainIntent = new Intent(BlockchainService.ACTION_RESET_BLOCKCHAIN, null, this, BlockchainServiceImpl.class);
walletFile = getFileStreamPath(Constants.Files.WALLET_FILENAME_PROTOBUF);
loadWalletFromProtobuf();
if (config.versionCodeCrossed(packageInfo.versionCode, VERSION_CODE_SHOW_BACKUP_REMINDER) && !wallet.getImportedKeys().isEmpty())
{
log.info("showing backup reminder once, because of imported keys being present");
config.armBackupReminder();
}
config.updateLastVersionCode(packageInfo.versionCode);
afterLoadWallet();
cleanupFiles();
}