Example usage for java.util.concurrent Executors newSingleThreadExecutor

List of usage examples for java.util.concurrent Executors newSingleThreadExecutor

Introduction

In this page you can find the example usage for java.util.concurrent Executors newSingleThreadExecutor.

Prototype

public static ExecutorService newSingleThreadExecutor() 

Source Link

Document

Creates an Executor that uses a single worker thread operating off an unbounded queue.

Usage

From source file:com.cloud.network.vpc.VpcManagerImpl.java

@DB
protected boolean deletePrivateGatewayFromTheDB(final PrivateGateway gateway) {
    // check if there are ips allocted in the network
    final long networkId = gateway.getNetworkId();

    vpcTxCallable.setGateway(gateway);// w ww.  java  2 s  .  c  o m

    final ExecutorService txExecutor = Executors.newSingleThreadExecutor();
    final Future<Boolean> futureResult = txExecutor.submit(vpcTxCallable);

    boolean deleteNetworkFinal;
    try {
        deleteNetworkFinal = futureResult.get();
        if (deleteNetworkFinal) {
            final User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
            final Account owner = _accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM);
            final ReservationContext context = new ReservationContextImpl(null, null, callerUser, owner);
            _ntwkMgr.destroyNetwork(networkId, context, false);
            s_logger.debug("Deleted private network id=" + networkId);
        }
    } catch (final InterruptedException e) {
        s_logger.error("deletePrivateGatewayFromTheDB failed to delete network id " + networkId + "due to => ",
                e);
    } catch (final ExecutionException e) {
        s_logger.error("deletePrivateGatewayFromTheDB failed to delete network id " + networkId + "due to => ",
                e);
    }

    return true;
}