Java Month daemonThread(Runnable runnable)

Here you can find the source of daemonThread(Runnable runnable)

Description

Create a daemon thread

License

Open Source License

Parameter

Parameter Description
runnable The runnable to execute in the background

Return

The unstarted thread

Declaration

public static Thread daemonThread(Runnable runnable) 

Method Source Code

//package com.java2s;
/**//from  w w  w .ja v  a2  s.  c  o m
 * Copyright 2016 LinkedIn Corp. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 */

public class Main {
    /**
     * Create a daemon thread
     *
     * @param runnable The runnable to execute in the background
     * @return The unstarted thread
     */
    public static Thread daemonThread(Runnable runnable) {
        return newThread(runnable, true);
    }

    /**
     * Create a daemon thread
     *
     * @param name The name of the thread
     * @param runnable The runnable to execute in the background
     * @return The unstarted thread
     */
    public static Thread daemonThread(String name, Runnable runnable) {
        return newThread(name, runnable, true);
    }

    /**
     * Create a new thread
     *
     * @param runnable The work for the thread to do
     * @param daemon Should the thread block JVM shutdown?
     * @return The unstarted thread
     */
    public static Thread newThread(Runnable runnable, boolean daemon) {
        Thread thread = new Thread(runnable);
        thread.setDaemon(daemon);
        thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
            public void uncaughtException(Thread t, Throwable e) {
                //error("Uncaught exception in thread '" + t.getName + "':", e)
            }
        });
        return thread;
    }

    /**
     * Create a new thread
     *
     * @param name The name of the thread
     * @param runnable The work for the thread to do
     * @param daemon Should the thread block JVM shutdown?
     * @return The unstarted thread
     */
    public static Thread newThread(String name, Runnable runnable, boolean daemon) {
        Thread thread = new Thread(runnable, name);
        thread.setDaemon(daemon);
        thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
            public void uncaughtException(Thread t, Throwable e) {
                e.printStackTrace();
            }
        });
        return thread;
    }
}

Related

  1. adjustWeekOfMonth(int eventWeekOfMonth, int eventRealWeekOfMonth)
  2. calculateMonthlyNominalInterestRate(final double effectiveInterestRate)
  3. checkMonth(int month)
  4. createDateMonth(String dateYear)
  5. createTestCCMonth()
  6. displayMonthlyPeriod(String week)
  7. doy2month(int year, int doy)
  8. extractMonthFromDate(String dateString)
  9. findMonth(String strMonth)