java callable code example

Example 1: what is a callable in java

public class EventLoggingTask implements  Runnable{
    private Logger logger
      = LoggerFactory.getLogger(EventLoggingTask.class);

    @Override
    public void run() {
        logger.info("Message");
    }
}

Example 2: what is a callable in java

public interface Runnable {
    public void run();
}

Example 3: what is a callable in java

public void executeTask() {
    executorService = Executors.newSingleThreadExecutor();
    Future future = executorService.submit(new EventLoggingTask());
    executorService.shutdown();
}

Tags:

Java Example