Java ThreadPoolExecutor executeInBackground(Runnable r)

Here you can find the source of executeInBackground(Runnable r)

Description

execute In Background

License

Open Source License

Declaration

public static synchronized void executeInBackground(Runnable r) 

Method Source Code

//package com.java2s;
/*/*  w  ww  .  j a va2  s  .  c  o m*/
 *    Copyright (C) 2008-2010 Igor Kriznar
 *    
 *    This file is part of GTD-Free.
 *    
 *    GTD-Free is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *    
 *    GTD-Free is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *    
 *    You should have received a copy of the GNU General Public License
 *    along with GTD-Free.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Main {
    private static ThreadPoolExecutor backgroundExecutor;

    public static synchronized void executeInBackground(Runnable r) {

        if (backgroundExecutor == null) {
            backgroundExecutor = new ThreadPoolExecutor(0, 1, 1, TimeUnit.SECONDS,
                    new LinkedBlockingQueue<Runnable>(), new ThreadFactory() {

                        @Override
                        public Thread newThread(Runnable r) {
                            Thread t = new Thread(r);
                            t.setName("BackgroundExecutor"); //$NON-NLS-1$
                            t.setPriority(Thread.MIN_PRIORITY);
                            t.setDaemon(false);
                            return t;
                        }
                    });
        }

        backgroundExecutor.execute(r);

    }
}

Related

  1. createExecutor()
  2. createExecutor(final String name, int count, int keepAlive, final boolean isDaemon)
  3. createQueue(final int queueCapacity)
  4. createScheduledThreadPoolExecutor(final int poolSz, final String threadName)
  5. createThreadPoolExecutor(final int queueSize, final String threadName)
  6. executeInDaemon(Runnable... run)
  7. getBlockingWorkExecutor()
  8. getBoundedThreadPoolExecutor(int maxPoolSize, long keepAliveTime, TimeUnit unit, ThreadFactory tFactory)
  9. getScheduler()