CoralThreads (Straight to the Point)

Below the basics of CoralThreads:

import com.coralblocks.coralthreads.Affinity;
 
public class Basics {
     
    public static void main(String[] args) throws Exception {
         
        Thread thread = new Thread(new Runnable() {
 
            @Override
            public void run() {
 
                // must be the first thing inside the run method
                Affinity.bind();
                 
                try {
                     
                    while(true) {
                         
                        // do whatever you want here...
                    }
                     
                } finally {
                     
                    // must be the last thing inside the run method
                    Affinity.unbind();
                }
            }
        }, "MyPinnedThread");
         
        System.out.println();
        Affinity.printSituation(); // nothing done yet...
         
        // assign thread to processor:
        int procToBind = Integer.parseInt(args[0]);
        Affinity.assignToProcessor(procToBind, thread);
         
        Affinity.printSituation(); // now you see it there...
         
        // start the thread!
        thread.start();
         
        Affinity.printSituation(); // now it is running with a pid...
    }
}