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:net.bluehornreader.service.FeedCrawlerService.java

FeedCrawlerService(LowLevelDbAccess lowLevelDbAccess) throws Exception {
    crawlerDb = new Crawler.DB(lowLevelDbAccess);
    crawler = crawlerDb.getCrawler(IP);/*from  w w  w .jav  a 2s .  co m*/
    while (crawler == null) {
        synchronized (this) {
            wait(1000);
        }
        crawlerDb.updateCrawl(IP, 0);
        crawler = crawlerDb.getCrawler(IP);
    }
    crawler.feedIdsSeq = -1; // to force feeds to be read
    feedDb = new Feed.DB(lowLevelDbAccess);
    articleDb = new Article.DB(lowLevelDbAccess);
    electionDb = new Election.DB(lowLevelDbAccess);
    //clearFeeds(); System.exit(1);

    for (int i = 0; i < Config.getConfig().threadsPerCrawler; ++i) {
        Thread t = new CrawlingThread();
        t.setDaemon(true);
        t.setName(String.format("CrawlingThread/%s/%s", IP, i));
        crawlingRunnables.add(t);
        t.start();
    }
}

From source file:org.jboss.bpm.report.BirtService.java

public void createAsync() {
    Thread t = new Thread(new Runnable() {
        public void run() {
            log.info("Creating BIRT service in the background");
            create();/*from   www .  j  a  va  2s .c  o m*/
        }
    });

    t.setName("BirtService-Init");
    t.start();
}

From source file:org.apache.hadoop.hbase.regionserver.CompactSplitThread.java

/** @param server */
CompactSplitThread(HRegionServer server) {
    super();/*from w w  w . j ava  2s  . c om*/
    this.server = server;
    this.conf = server.getConfiguration();
    this.regionSplitLimit = conf.getInt("hbase.regionserver.regionSplitLimit", Integer.MAX_VALUE);

    int largeThreads = Math.max(1, conf.getInt("hbase.regionserver.thread.compaction.large", 1));
    int smallThreads = conf.getInt("hbase.regionserver.thread.compaction.small", 1);

    int splitThreads = conf.getInt("hbase.regionserver.thread.split", 1);

    // if we have throttle threads, make sure the user also specified size
    Preconditions.checkArgument(largeThreads > 0 && smallThreads > 0);

    final String n = Thread.currentThread().getName();

    this.longCompactions = new ThreadPoolExecutor(largeThreads, largeThreads, 60, TimeUnit.SECONDS,
            new PriorityBlockingQueue<Runnable>(), new ThreadFactory() {
                @Override
                public Thread newThread(Runnable r) {
                    Thread t = new Thread(r);
                    t.setName(n + "-longCompactions-" + System.currentTimeMillis());
                    return t;
                }
            });
    this.longCompactions.setRejectedExecutionHandler(new Rejection());
    this.shortCompactions = new ThreadPoolExecutor(smallThreads, smallThreads, 60, TimeUnit.SECONDS,
            new PriorityBlockingQueue<Runnable>(), new ThreadFactory() {
                @Override
                public Thread newThread(Runnable r) {
                    Thread t = new Thread(r);
                    t.setName(n + "-shortCompactions-" + System.currentTimeMillis());
                    return t;
                }
            });
    this.shortCompactions.setRejectedExecutionHandler(new Rejection());
    this.splits = (ThreadPoolExecutor) Executors.newFixedThreadPool(splitThreads, new ThreadFactory() {
        @Override
        public Thread newThread(Runnable r) {
            Thread t = new Thread(r);
            t.setName(n + "-splits-" + System.currentTimeMillis());
            return t;
        }
    });
    int mergeThreads = conf.getInt("hbase.regionserver.thread.merge", 1);
    this.mergePool = (ThreadPoolExecutor) Executors.newFixedThreadPool(mergeThreads, new ThreadFactory() {
        @Override
        public Thread newThread(Runnable r) {
            Thread t = new Thread(r);
            t.setName(n + "-merges-" + System.currentTimeMillis());
            return t;
        }
    });
}

From source file:edu.umass.cs.nio.JSONMessenger.java

/**
 * @param niot//  w ww .  ja  v  a2s.  com
 * @param numWorkers
 */
@SuppressWarnings("unchecked")
public JSONMessenger(final InterfaceNIOTransport<NodeIDType, JSONObject> niot, int numWorkers) {
    // to not create thread pools unnecessarily
    if (niot instanceof JSONMessenger)
        this.execpool = ((JSONMessenger<NodeIDType>) niot).execpool;
    else
        this.execpool = Executors.newScheduledThreadPool(5, new ThreadFactory() {
            @Override
            public Thread newThread(Runnable r) {
                Thread thread = Executors.defaultThreadFactory().newThread(r);
                thread.setName(JSONMessenger.class.getSimpleName() + niot.getMyID() + thread.getName());
                return thread;
            }
        });
    nioTransport = (InterfaceNIOTransport<NodeIDType, JSONObject>) niot;

    this.workers = new MessageNIOTransport[numWorkers];
    for (int i = 0; i < workers.length; i++) {
        try {
            log.info((this + " starting worker with ssl mode " + this.nioTransport.getSSLMode()));
            this.workers[i] = new MessageNIOTransport<NodeIDType, JSONObject>(null, this.getNodeConfig(),
                    this.nioTransport.getSSLMode());
            this.workers[i].setName(JSONMessenger.class.getSimpleName() + niot.getMyID() + "_send_worker" + i);
        } catch (IOException e) {
            this.workers[i] = null;
            e.printStackTrace();
        }
    }
}

From source file:com.microsoft.tfs.client.common.ui.teambuild.teamexplorer.sections.TeamExplorerBuildsMyBuildsSection.java

@Override
public Composite getSectionContent(final FormToolkit toolkit, final Composite parent, final int style,
        final TeamExplorerContext context) {
    this.toolkit = toolkit;
    composite = toolkit.createComposite(parent);

    // Form-style border painting not enabled (0 pixel margins OK) because
    // no applicable controls in this composite
    SWTUtil.gridLayout(composite, 1, true, 0, 5);

    if (!context.isConnected()) {
        createDisconnectedContent(toolkit, composite);
        return composite;
    } else if (buildItems.length == 0) {
        createEmptyLabel(toolkit, composite);
    } else {/*w w  w.j  a  v a  2  s .c o  m*/
        createTableViewer(toolkit, composite);
    }

    // Create a background worker thread that will perform an automatic
    // refresh for this section.
    final Thread refreshThread = new Thread(new MyBuildsRefreshWorker());
    refreshThread.setName("My Builds Auto Refresh"); //$NON-NLS-1$
    refreshThread.start();

    // Add build changes listeners to allow refresh updates in the UI.
    BuildHelpers.getBuildManager().addBuildManagerListener(buildManagerListener);

    // Handle disposal of this control.
    composite.addDisposeListener(new DisposeListener() {
        @Override
        public void widgetDisposed(final DisposeEvent e) {
            refreshThreadStop = true;
            refreshThread.interrupt();
            imageHelper.dispose();
            BuildHelpers.getBuildManager().removeBuildManagerListener(buildManagerListener);
        }
    });

    return composite;
}

From source file:com.codefollower.lealone.omid.tso.TSOHandler.java

/**
 * Constructor//from  w  w w  .  j  a v  a2 s. c  o m
 * @param channelGroup
 */
public TSOHandler(ChannelGroup channelGroup, TSOState state, int batchSize) {
    this.channelGroup = channelGroup;
    this.timestampOracle = state.getTimestampOracle();
    this.sharedState = state;

    this.flushThread = new FlushThread();
    this.scheduledExecutor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
        @Override
        public Thread newThread(Runnable r) {
            Thread t = new Thread(Thread.currentThread().getThreadGroup(), r);
            t.setDaemon(true);
            t.setName("Flush Thread");
            return t;
        }
    });
    this.batchSize = batchSize;
}

From source file:com.tascape.qa.th.Utils.java

/**
 *
 * @param path          directory to clean
 * @param keepAliveHour any file/directory having last modified time longer than keepAliveHour will be deleted
 * @param namePrefix    file name prefix
 *///from   w  w  w.ja  v a2 s.  c  om
public static void cleanDirectory(final String path, final float keepAliveHour, final String namePrefix) {
    final long intervalMillis = 3600000;
    final File dir = new File(path);
    if (!dir.exists()) {
        return;
    }
    Thread thread = new Thread() {
        @Override
        public void run() {
            while (true) {
                long lastModifiedMillis = (long) (System.currentTimeMillis() - keepAliveHour * 3600000);
                Collection<File> files = FileUtils.listFiles(dir, null, true);
                for (File file : files) {
                    if (file.lastModified() < lastModifiedMillis && file.getName().startsWith(namePrefix)) {
                        LOG.debug("Delete {}", file);
                        if (!FileUtils.deleteQuietly(file)) {
                            LOG.debug("Cannot delete {}", file);
                        }
                    }
                }
                try {
                    LOG.debug("Waiting for next cleanup...");
                    Thread.sleep(intervalMillis);
                } catch (InterruptedException ex) {
                    LOG.warn(ex.getMessage());
                    return;
                }
            }
        }
    };
    thread.setName(Thread.currentThread().getName() + "-cleaning-" + thread.hashCode());
    thread.setDaemon(true);
    LOG.info(
            "Starting directory cleaning thread (scanning hourly), all files/directories in {} and older than {} "
                    + "hour(s) and starts with {} will be deleted",
            dir, keepAliveHour, namePrefix);
    thread.start();
}

From source file:com.chicm.cmraft.log.DefaultRaftLog.java

private void startFlushWorker() {
    Thread t = new Thread(new LogFlushWorker());
    t.setName("LogFlushWorker");
    t.start();/*from www. ja v  a2 s.c o  m*/
}

From source file:org.springframework.osgi.extender.internal.support.ExtenderConfiguration.java

private TaskExecutor createDefaultShutdownTaskExecutor() {
    ThreadPoolTaskScheduler taskExecutor = new ThreadPoolTaskScheduler() {
        private static final long serialVersionUID = 1L;

        protected ScheduledExecutorService createExecutor(int poolSize, final ThreadFactory threadFactory,
                RejectedExecutionHandler rejectedExecutionHandler) {

            ThreadFactory tf = new ThreadFactory() {
                public Thread newThread(Runnable r) {
                    Thread t = threadFactory.newThread(r);
                    t.setName("Spring DM context shutdown thread");
                    return t;
                }/*from w w  w. ja va2  s.  c o m*/

            };

            return new ScheduledThreadPoolExecutor(poolSize, tf, rejectedExecutionHandler);
        }
    };
    taskExecutor.afterPropertiesSet();
    isShutdownTaskExecutorManagedInternally = true;
    return taskExecutor;
}

From source file:mServer.crawler.sender.MediathekArd.java

@Override
protected void addToList() {
    listeThemen.clear();/*from  ww  w.  ja va  2s.co  m*/
    addThema();
    listeThemen.addUrl(new String[] { THEMA_TAGE, "" });
    if (Config.getStop() || listeThemen.isEmpty()) {
        meldungThreadUndFertig();
    } else {
        meldungAddMax(listeThemen.size());
        listeSort(listeThemen, 1);
        for (int t = 0; t < getMaxThreadLaufen(); ++t) {
            Thread th = new ThemaLaden();
            th.setName(SENDERNAME + t);
            th.start();
        }
    }
}