Is there anyway one kernel thread can switch between compute intensive tasks?

kant kodali kanth909 at
Thu Jan 25 09:51:07 UTC 2018

I am trying to see if there anyway a single thread in Java can switch
between tasks where each task is an infinite loop ?

I have the following code and I am wondering if there is any possible way I
could make the count for all three jobs below change while they run on
single thread? perhaps using wait/notify/interrupt (whatever it takes)?

import java.util.concurrent.ExecutorService;import
class Job implements Runnable {
    protected int count;
    public Job(){
        this.count = 0;

    public void run() {
        while(true) {
           this.count = this.count + 1;

public class ThreadTest {

    static int tasks = 3;
    static Job[] jobs = new Job[3];

    public static void main(String[] args) {
        ExecutorService executor = Executors.newFixedThreadPool(1);
        for (int i = 0; i < tasks; i++) {
            jobs[i] = new Job();

        while (!executor.isTerminated()) {
           for (int i = 0; i < tasks; i++) {
              System.out.print(jobs[i].c + " ");
           try { Thread.sleep(1000); } catch (InterruptedException ex) { }

If you actually run the program the count will only change for one job but
not for all three jobs. But if I use green threads in Golang and assign
each green thread an infinite loop they are able to switch however what I
don't understand is that once a green thread assigns a kernel thread to run
one infinite loop how come other green threads were able to schedule on the
same kernel thread? can someone enlighten me here? Sorry if my question is

Thanks much!

More information about the loom-dev mailing list