Example usage for java.lang Thread Thread

List of usage examples for java.lang Thread Thread

Introduction

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

Prototype

public Thread(Runnable target, String name) 

Source Link

Document

Allocates a new Thread object.

Usage

From source file:Main.java

public static void run(Runnable runnable, String threadName, boolean daemon) {

    Thread thread = new Thread(runnable, threadName);

    thread.setName(threadName);/*from   w w w  .j a v a2s. c  o m*/

    thread.setDaemon(daemon);

    thread.start();
}

From source file:Main.java

public static Thread fork(String name, Runnable r) {
    Thread thread = new Thread(r, name);
    thread.start();/* w w w . ja va  2 s . c o m*/
    return thread;
}

From source file:Main.java

public static void start(Runnable executer, String threadName, boolean demon) {
    Thread thread = new Thread(executer, threadName);
    thread.setDaemon(demon);/*from  w w  w  .  j a  va2s.c  o m*/
    thread.start();
}

From source file:com.sm.store.TestStoreCases.java

public static void main(String[] args) {
    TestStoreCases client = createClient(args);
    if (client.threads <= 1)
        // create a client that executes operations on a single store
        client.runTest(client.tests);/*w  w  w  .  ja  v a 2 s.c o m*/
    else {
        if (checkThread(client.tests)) {
            for (int i = 0; i < client.threads; i++) {
                new Thread(new RunThread(client, client.tests), "thread-" + i).start();
            }
        }
    }

}

From source file:Main.java

public static ThreadFactory setThreadName(String name) {
    return (Runnable r) -> new Thread(r, name);
}

From source file:Main.java

public static ThreadFactory setThreadNameWithID(String name) {
    return (Runnable r) -> new Thread(r, String.format("%s-%s", name, r.hashCode()));
}

From source file:Main.java

public static void runOnNewThread(Runnable runnable, String threadName) {
    new Thread(runnable, threadName).start();
}

From source file:com.minoritycode.Application.java

public static void main(String[] args) {
    System.out.println("Trello Backup Application");

    File configFile = new File(workingDir + "\\config.properties");
    InputStream input = null;/*from  w w  w.  j  av  a2 s  . c  om*/
    try {
        input = new FileInputStream(configFile);
        config.load(input);
        input.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    //        String workingDir = System.getProperty("user.dir");
    manualOperation = Boolean.parseBoolean(config.getProperty("manualOperation"));

    logger.startErrorLogger();
    setBackupDir();

    try {
        report.put("backupDate", backupDate);
    } catch (JSONException e) {
        e.printStackTrace();
        logger.logLine(e.getMessage());
    }

    lock = new ReentrantLock();
    lockErrorRep = new ReentrantLock();
    lockErrorLog = new ReentrantLock();

    Application.key = config.getProperty("trellokey");
    Application.token = config.getProperty("trellotoken");

    boolean useProxy = Boolean.parseBoolean(config.getProperty("useProxy"));

    boolean proxySet = true;

    if (useProxy) {
        proxySet = setProxy();
    }

    //        GUI  swingContainerDemo = new GUI();
    //        swingContainerDemo.showJPanelDemo();
    if (proxySet) {
        Credentials credentials = new Credentials();
        if (Application.key.isEmpty()) {
            Application.key = credentials.getKey();
        } else {
            Application.key = config.getProperty("trellokey");
        }
        if (token.isEmpty()) {
            Application.token = credentials.getToken();
        } else {
            Application.token = config.getProperty("trellotoken");
        }

        BoardDownloader downloader = new BoardDownloader();

        downloader.downloadMyBoard(url);
        boards = downloader.downloadOrgBoard(url);

        if (boards != null) {
            try {
                report.put("boardNum", boards.size());
            } catch (JSONException e) {
                e.printStackTrace();
                logger.logLine(e.getMessage());
            }

            Integer numberOfThreads = Integer.parseInt(config.getProperty("numberOfThreads"));

            if (numberOfThreads == null) {
                logger.logLine("error number of threads not set in config file");
                if (manualOperation) {
                    String message = "How many threads do you want to use (10) is average";
                    numberOfThreads = Integer.parseInt(Credentials.getInput(message));
                    Credentials.saveProperty("numberOfThreads", numberOfThreads.toString());
                } else {
                    if (Boolean.parseBoolean(config.getProperty("useMailer"))) {
                        Mailer mailer = new Mailer();
                        mailer.SendMail();
                    }
                    System.exit(-1);
                }
            }

            ArrayList<Thread> threadList = new ArrayList<Thread>();
            for (int i = 0; i < numberOfThreads; i++) {
                Thread thread = new Thread(new Application(), "BoardDownloadThread");
                threadList.add(thread);
                thread.start();
            }
        } else {
            //create empty report
            try {
                report.put("boardsNotDownloaded", "99999");
                report.put("boardNum", 0);
                report.put("boardNumSuccessful", 0);
            } catch (JSONException e) {
                e.printStackTrace();
                logger.logLine(e.getMessage());
            }

            if (Boolean.parseBoolean(config.getProperty("useMailer"))) {
                Mailer mailer = new Mailer();
                mailer.SendMail();
            }

            logger.logger(report);
        }
    } else {
        //create empty report
        try {
            report.put("boardsNotDownloaded", "99999");
            report.put("boardNum", 0);
            report.put("boardNumSuccessful", 0);
        } catch (JSONException e) {
            e.printStackTrace();
            logger.logLine(e.getMessage());
        }

        if (Boolean.parseBoolean(config.getProperty("useMailer"))) {

            Mailer mailer = new Mailer();
            mailer.SendMail();
        }
    }
}

From source file:Main.java

public static Thread createThread(Runnable runnable, String threadName) {
    return new Thread(runnable, threadName);
}

From source file:Main.java

public static Thread newThread(Runnable r, String name) {
    if (TextUtils.isEmpty(name)) {
        throw new RuntimeException("thread name should not be empty");
    }//  w  ww . j  a  va2 s . com
    return new Thread(r, getStandardThreadName(name));
}