Menu

ThreadEngineApi examples

Geir Sande


package net.sf.perftence.concurrent;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ThreadEngineApiExample {

private final static Logger LOG = LoggerFactory
        .getLogger(ThreadEngineApiExample.class);

@SuppressWarnings("static-method")
@Test
public void example() {
    final Runnable runnable = new Runnable() {

        @Override
        public void run() {
            log().info("My runnable got run. Nice :)");
        }

    };
    new ThreadEngineApi<Runnable>().with("threadname-prefix")
            .with(runnable).run();
}

private static Logger log() {
    return LOG;
}

}

This would printout the following to the console:

DEBUG | main | ThreadEngine.java: 63 | Starting threads...
DEBUG | main | ThreadEngine.java: 67 | Threads started.
INFO | threadname-prefix0 | ThreadEngineApiExample.java: 19 | My runnable got run. Nice :)
DEBUG | main | ThreadEngine.java: 44 | Threads 'cleared'.


Related

Wiki: Home

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.