Example usage for java.util.concurrent Executors defaultThreadFactory

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

Introduction

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

Prototype

public static ThreadFactory defaultThreadFactory() 

Source Link

Document

Returns a default thread factory used to create new threads.

Usage

From source file:com.yahoo.pasc.paxos.client.PaxosClient.java

public static void main(String[] args) throws Exception {

    CommandLineParser parser = new PosixParser();
    Options options;// www  .jav a  2s.c o m

    {
        Option id = new Option("i", true, "client id");
        Option clients = new Option("c", true, "number of clients");
        Option host = new Option("l", true, "leader (hostname:port)");
        Option servers = new Option("s", true, "number of servers");
        Option quorum = new Option("q", true, "necesarry quorum at the client");
        Option port = new Option("p", true, "port used by client");
        Option buffer = new Option("b", true, "number of concurrent clients");
        Option timeout = new Option("t", true, "timeout in milliseconds");
        Option udp = new Option("u", false, "use UDP");
        Option zookeeper = new Option("z", true, "zookeeper connection string");
        Option warmup = new Option("w", true, "warmup messagges");
        Option measuring = new Option("m", true, "measuring time");
        Option request = new Option("r", true, "request size");
        Option frequency = new Option("f", true, "frequency of throughput info");
        Option anm = new Option("a", false, "use protection");
        Option inlineThresh = new Option("n", true, "threshold for sending requests iNline with accepts ");
        Option asynSize = new Option("y", true, "size of async messages queue");

        options = new Options();
        options.addOption(id).addOption(host).addOption(servers).addOption(quorum).addOption(port)
                .addOption(warmup).addOption(buffer).addOption(timeout).addOption(udp).addOption(zookeeper)
                .addOption(clients).addOption(measuring).addOption(request).addOption(frequency).addOption(anm)
                .addOption(inlineThresh).addOption(asynSize);
    }

    CommandLine line = null;
    try {
        line = parser.parse(options, args);

        String host = line.hasOption('l') ? line.getOptionValue('l')
                : "localhost:20548,localhost:20748,localhost:20778";
        String zkConnection = line.hasOption('z') ? line.getOptionValue('z') : "localhost:2181";
        int clientIds = line.hasOption('i') ? Integer.parseInt(line.getOptionValue('i')) : 0;
        int servers = line.hasOption('s') ? Integer.parseInt(line.getOptionValue('s')) : 3;
        int quorum = line.hasOption('q') ? Integer.parseInt(line.getOptionValue('q')) : 1;
        int buffer = line.hasOption('b') ? Integer.parseInt(line.getOptionValue('b')) : 1;
        int timeout = line.hasOption('t') ? Integer.parseInt(line.getOptionValue('t')) : 5000;
        int clients = line.hasOption('c') ? Integer.parseInt(line.getOptionValue('c')) : 1;
        int requestSize = line.hasOption('r') ? Integer.parseInt(line.getOptionValue('r')) : 0;
        int inlineThreshold = line.hasOption('n') ? Integer.parseInt(line.getOptionValue('n')) : 1000;
        int asynSize = line.hasOption('y') ? Integer.parseInt(line.getOptionValue('y')) : 100;
        boolean protection = line.hasOption('a');

        int threads = Runtime.getRuntime().availableProcessors() * 2;
        final ExecutionHandler executor = new ExecutionHandler(new OrderedMemoryAwareThreadPoolExecutor(threads,
                1024 * 1024, 1024 * 1024 * 1024, 30, TimeUnit.SECONDS, Executors.defaultThreadFactory()));

        String[] serverHosts = host.split(",");

        ServerHelloHandler shello = new ServerHelloHandler();
        ReplyHandler reply = new ReplyHandler();
        SubmitHandler submit = new SubmitHandler();
        TimeoutHandler tout = new TimeoutHandler();
        AsyncMessageHandler asyncm = new AsyncMessageHandler();
        ByeHandler bye = new ByeHandler();
        HelloHandler hello = new HelloHandler();

        Random rnd = new Random();

        for (int i = 0; i < buffer; ++i) {
            ClientState clientState = new ClientState(servers, quorum, inlineThreshold, asynSize);
            final PascRuntime<ClientState> runtime = new PascRuntime<ClientState>(protection);
            runtime.setState(clientState);
            runtime.addHandler(ServerHello.class, shello);
            runtime.addHandler(Reply.class, reply);
            runtime.addHandler(Submit.class, submit);
            runtime.addHandler(Timeout.class, tout);
            runtime.addHandler(AsyncMessage.class, asyncm);
            runtime.addHandler(Bye.class, bye);
            runtime.addHandler(Hello.class, hello);

            final PaxosClientHandler handler = new PaxosClientHandler(runtime, new SimpleClient(requestSize),
                    serverHosts, clients, timeout, zkConnection, executor);

            if (line.hasOption('w'))
                handler.setWarmup(Integer.parseInt(line.getOptionValue('w')));
            if (line.hasOption('m'))
                handler.setMeasuringTime(Integer.parseInt(line.getOptionValue('m')));
            if (line.hasOption('f'))
                handler.setPeriod(Integer.parseInt(line.getOptionValue('f')));

            handler.start();

            Thread.sleep(rnd.nextInt(200));
        }
    } catch (Exception e) {
        System.err.println("Unexpected exception " + e);
        e.printStackTrace();

        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("Paxos", options);

        System.exit(-1);
    }
}

From source file:Main.java

public static Thread getDaemonThread(Runnable runnable) {
    Thread thread = Executors.defaultThreadFactory().newThread(runnable);
    thread.setDaemon(true);// www . j a  v  a 2s . co m
    return thread;
}

From source file:Main.java

protected static synchronized ThreadFactory getThreadFactory() {
    return null != tdfContainer ? tdfContainer : (tdfContainer = Executors.defaultThreadFactory());
}

From source file:xyz.cloudbans.client.Clients.java

public static Client create(ClientConfig config) {
    return create(Executors.defaultThreadFactory(), config);
}

From source file:Main.java

/**
 * Based on the default thread factory/*from w w w  . j  a  va 2 s .co  m*/
 *
 * @param name
 *            the name prefix of the new thread
 * @return the factory to use when creating new threads
 */
public static final ThreadFactory getThreadFactory(String name) {
    return r -> {
        Thread t = Executors.defaultThreadFactory().newThread(r);
        t.setName(name + "-" + t.getName()); //$NON-NLS-1$
        return t;
    };
}

From source file:io.github.mmichaelis.selenium.client.provider.internal.QuitWebDriverRunnableTest.java

@Test
public void quit_webdriver_when_running() throws Exception {
    final Runnable runnable = new QuitWebDriverRunnable(driver);
    final Thread thread = Executors.defaultThreadFactory().newThread(runnable);
    thread.start();/*from w w w .  j  a va2  s . co m*/
    thread.join();
    verify(driver, atLeastOnce()).quit();
}

From source file:org.apache.tajo.HttpFileServer.java

public HttpFileServer(final InetSocketAddress addr) {
    this.addr = addr;
    this.eventloopGroup = new NioEventLoopGroup(2, Executors.defaultThreadFactory());

    // Configure the server.
    this.bootstrap = new ServerBootstrap();
    this.bootstrap.childHandler(new HttpFileServerChannelInitializer()).group(eventloopGroup)
            .option(ChannelOption.TCP_NODELAY, true).channel(NioServerSocketChannel.class);
    this.channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
}

From source file:de.jackwhite20.japs.client.pub.impl.PublisherImpl.java

public PublisherImpl(List<ClusterServer> clusterServers) {

    super(clusterServers);

    this.executorService = Executors.newSingleThreadExecutor(r -> {
        Thread thread = Executors.defaultThreadFactory().newThread(r);
        thread.setName("AsyncPublisher Thread");

        return thread;
    });/*  w w w .  j  a  va 2 s  . c om*/
    this.asyncPublisher = new AsyncPublisherImpl(executorService, this);
}

From source file:io.selendroid.server.SelendroidStandaloneServer.java

/**
 * for testing only//from w  w  w . ja  v a2s.c  om
 * 
 * @throws AndroidSdkException
 */
protected SelendroidStandaloneServer(SelendroidConfiguration configuration, SelendroidStandaloneDriver driver)
        throws AndroidSdkException {
    this.configuration = configuration;
    this.driver = driver;
    NamingThreadFactory namingThreadFactory = new NamingThreadFactory(Executors.defaultThreadFactory(),
            "selendroid-standalone-handler");
    webServer = WebServers.createWebServer(Executors.newCachedThreadPool(namingThreadFactory),
            new InetSocketAddress(configuration.getPort()), URI.create("http://127.0.0.1"
                    + (configuration.getPort() == 80 ? "" : (":" + configuration.getPort())) + "/"));
    init();
}

From source file:org.sonews.daemon.async.AsynchronousNNTPDaemon.java

@Override
public void run() {
    try {//from  www .j ava 2  s .  co  m
        final int workerThreads = Math.max(4, 2 * Runtime.getRuntime().availableProcessors());
        channelGroup = AsynchronousChannelGroup.withFixedThreadPool(workerThreads,
                Executors.defaultThreadFactory());

        serverSocketChannel = AsynchronousServerSocketChannel.open(channelGroup);
        serverSocketChannel.bind(new InetSocketAddress(port));

        serverSocketChannel.accept(null, new AcceptCompletionHandler(serverSocketChannel));

        channelGroup.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
    } catch (IOException | InterruptedException ex) {
        Log.get().log(Level.SEVERE, ex.getLocalizedMessage(), ex);
    }
}