当前位置: 首页>>代码示例>>Java>>正文


Java Threading.uncaughtExceptionHandler方法代码示例

本文整理汇总了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();
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:17,代码来源:PeerSocketHandler.java

示例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();
    }
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:21,代码来源:Wallet.java

示例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;
        }
    };
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:34,代码来源:WalletFiles.java

示例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;
        }
    };
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:34,代码来源:WalletFiles.java

示例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);
        }
    }
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:16,代码来源:Wallet.java

示例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();
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:60,代码来源:WalletApplication.java

示例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();
}
 
开发者ID:soapboxsys,项目名称:ombuds-android,代码行数:56,代码来源:WalletApplication.java


注:本文中的org.bitcoinj.utils.Threading.uncaughtExceptionHandler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。