Example usage for java.lang Thread setName

List of usage examples for java.lang Thread setName

Introduction

In this page you can find the example usage for java.lang Thread setName.

Prototype

public final synchronized void setName(String name) 

Source Link

Document

Changes the name of this thread to be equal to the argument name .

Usage

From source file:org.apache.nifi.processor.util.listen.AbstractListenEventProcessor.java

@OnScheduled
public void onScheduled(final ProcessContext context) throws IOException {
    charset = Charset.forName(context.getProperty(CHARSET).getValue());
    port = context.getProperty(PORT).asInteger();
    events = new LinkedBlockingQueue<>(context.getProperty(MAX_MESSAGE_QUEUE_SIZE).asInteger());

    final String nicIPAddressStr = context.getProperty(NETWORK_INTF_NAME).evaluateAttributeExpressions()
            .getValue();//from www .j  av  a 2 s  .c om
    final int maxChannelBufferSize = context.getProperty(MAX_SOCKET_BUFFER_SIZE).asDataSize(DataUnit.B)
            .intValue();

    InetAddress nicIPAddress = null;
    if (!StringUtils.isEmpty(nicIPAddressStr)) {
        NetworkInterface netIF = NetworkInterface.getByName(nicIPAddressStr);
        nicIPAddress = netIF.getInetAddresses().nextElement();
    }

    // create the dispatcher and call open() to bind to the given port
    dispatcher = createDispatcher(context, events);
    dispatcher.open(nicIPAddress, port, maxChannelBufferSize);

    // start a thread to run the dispatcher
    final Thread readerThread = new Thread(dispatcher);
    readerThread.setName(getClass().getName() + " [" + getIdentifier() + "]");
    readerThread.setDaemon(true);
    readerThread.start();
}

From source file:edu.umass.cs.gigapaxos.FailureDetection.java

FailureDetection(NodeIDType id, InterfaceNIOTransport<NodeIDType, JSONObject> niot, String paxosLogFolder) {
    nioTransport = niot;//from  w  w  w .  java2  s  . co m
    myID = id;
    this.execpool = Executors.newScheduledThreadPool(1, new ThreadFactory() {
        @Override
        public Thread newThread(Runnable r) {
            Thread thread = Executors.defaultThreadFactory().newThread(r);
            thread.setName(FailureDetection.class.getSimpleName() + myID);
            return thread;
        }
    });
    lastHeardFrom = new ConcurrentHashMap<NodeIDType, Long>();
    keepAliveTargets = new TreeSet<NodeIDType>();
    futures = new HashMap<NodeIDType, ScheduledFuture<PingTask>>();
    initialize(paxosLogFolder);
}

From source file:com.gs.jrpip.client.ThankYouWriter.java

private synchronized void startThankYouThread() {
    if (this.done) {
        this.done = false;
        Thread thankYouThread = new Thread(INSTANCE);
        thankYouThread.setName("JRPIP Thank You Thread");
        thankYouThread.setDaemon(true);//from w w  w  .  ja v a 2  s .c  om
        thankYouThread.start();
    }
}

From source file:org.apache.atlas.web.filters.AuditFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
        throws IOException, ServletException {
    final String requestTimeISO9601 = DateTimeHelper.formatDateUTC(new Date());
    final HttpServletRequest httpRequest = (HttpServletRequest) request;
    final String requestId = UUID.randomUUID().toString();
    final Thread currentThread = Thread.currentThread();
    final String oldName = currentThread.getName();
    String user = getUserFromRequest(httpRequest);

    try {/*from  w w w  .  ja  v  a2 s  . c  om*/
        currentThread.setName(formatName(oldName, requestId));
        RequestContext requestContext = RequestContext.createContext();
        requestContext.setUser(user);
        recordAudit(httpRequest, requestTimeISO9601, user);
        filterChain.doFilter(request, response);
    } finally {
        // put the request id into the response so users can trace logs for this request
        ((HttpServletResponse) response).setHeader(AtlasClient.REQUEST_ID, requestId);
        currentThread.setName(oldName);
        recordMetrics();
        RequestContext.clear();
        RequestContextV1.clear();
    }
}

From source file:org.apache.hadoop.yarn.server.TestYarnSSLServer.java

@Test
public void testSubmitApplication() throws Exception {
    GetNewApplicationRequest newAppReq = GetNewApplicationRequest.newInstance();
    GetNewApplicationResponse newAppRes = acClient.getNewApplication(newAppReq);
    ApplicationSubmissionContext appCtx = Records.newRecord(ApplicationSubmissionContext.class);
    //appCtx.setApplicationId(ApplicationId.newInstance(0L, 1));
    appCtx.setApplicationId(newAppRes.getApplicationId());
    appCtx.setApplicationName("RandomApplication");
    appCtx.setApplicationType("SomeType");

    Map<String, LocalResource> localResources = new HashMap<>();
    LocalResource lr = LocalResource.newInstance(URL.newInstance("hdfs://", "localhost", 8020, "aFile"),
            LocalResourceType.FILE, LocalResourceVisibility.PUBLIC, 100L, 100L);
    localResources.put("aFile", lr);

    Map<String, String> env = new HashMap<>();
    env.put("env0", "someValue");

    List<String> amCommnads = new ArrayList<>();
    amCommnads.add("someRandom --command");

    ContainerLaunchContext amCtx = ContainerLaunchContext.newInstance(localResources, env, amCommnads, null,
            null, null);//from  w w w. j av a  2s  .com

    appCtx.setAMContainerSpec(amCtx);
    appCtx.setResource(Resource.newInstance(2048, 2));
    appCtx.setQueue("default");

    ApplicationClientProtocol client = ClientRMProxy.createRMProxy(conf, ApplicationClientProtocol.class, true);

    Thread invoker = new Thread(new Invoker(client));
    invoker.setName("AnotherClient");
    invoker.start();
    SubmitApplicationRequest appReq = SubmitApplicationRequest.newInstance(appCtx);
    LOG.debug("Submitting the application");
    acClient.submitApplication(appReq);
    LOG.debug("Submitted the application");

    LOG.debug("Getting new application");
    newAppRes = acClient.getNewApplication(newAppReq);
    assertNotNull(newAppRes);
    LOG.debug("I have gotten the new application");

    List<ApplicationReport> appsReport = acClient.getApplications(GetApplicationsRequest.newInstance())
            .getApplicationList();
    boolean found = false;

    for (ApplicationReport appRep : appsReport) {
        if (appRep.getApplicationId().equals(appCtx.getApplicationId())) {
            found = true;
            break;
        }
    }

    assertTrue(found);
    TimeUnit.SECONDS.sleep(10);
}

From source file:com.photon.maven.plugins.android.standalonemojos.RobotiumMultiDeviceExecutorMojo.java

private void startThread(final DeviceCallback deviceCallback, final IDevice idevice) {
    try {//w  w  w.ja va2s. com
        Thread t = new RobitiumPerformanceTestRunner(deviceCallback, idevice);
        t.setName(idevice.getSerialNumber());
        t.start();
        threadObj.add(t);
        //         getLog().info(t.getName() + ": thread started");
        Thread.sleep(2000);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.wallabystreet.kinjo.common.transport.protocol.jxta.JXTAPeer.java

@Override
public Discovery discoverServiceProviders(ServiceDescriptor s, PropertyChangeListener l) {
    DiscoveryHandler h = new com.wallabystreet.kinjo.common.transport.protocol.jxta.JXTADiscoveryHandler(
            this.group, s);

    Discovery d = new Discovery(h);
    d.addObserver(l);/*w  w  w  . j a  va2s. c  om*/

    h.setSink(d);

    Thread handler = new Thread(h);
    handler.setName(s.getName() + " (search handler)");
    log.debug("starting discovery thread");
    handler.start();

    return d;
}

From source file:org.apache.hama.bsp.GroomServer.java

public static Thread startGroomServer(final GroomServer hrs, final String name) {
    Thread t = new Thread(hrs);
    t.setName(name);
    t.start();/* w  w w  .  j  a  v a  2s. c o m*/
    return t;
}

From source file:com.linkedin.pinot.controller.helix.core.relocation.RealtimeSegmentRelocator.java

public RealtimeSegmentRelocator(PinotHelixResourceManager pinotHelixResourceManager, ControllerConf config) {
    _pinotHelixResourceManager = pinotHelixResourceManager;
    _helixManager = pinotHelixResourceManager.getHelixZkManager();
    _helixAdmin = pinotHelixResourceManager.getHelixAdmin();
    _runFrequencySeconds = getRunFrequencySeconds(config.getRealtimeSegmentRelocatorFrequency());

    _executorService = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
        @Override/*  www.  ja v a2  s .  c om*/
        public Thread newThread(Runnable runnable) {
            Thread thread = new Thread(runnable);
            thread.setName("RealtimeSegmentRelocatorExecutorService");
            return thread;
        }
    });
}

From source file:com.mgmtp.jfunk.core.JFunk.java

private ExecutorService createExecutorService() {
    return new FixedSizeThreadExecutor(min(threadCount, scripts.size()), new ThreadFactory() {
        private final AtomicInteger threadNumber = new AtomicInteger(1);

        @Override/*from   www  . j ava  2  s  . co m*/
        public Thread newThread(final Runnable r) {
            int id = threadNumber.getAndIncrement();
            String threadName = StringUtils.leftPad(String.valueOf(id), 2, "0");
            Thread th = new Thread(r);
            th.setName(threadName);
            return th;
        }
    });
}