Facing problem executing the loom code.

Priyanka Thakur priyanka.thakur at knoldus.com
Sun Aug 23 15:44:27 UTC 2020


Hi,
I want to discuss the how can I execute the Loom code on My machine.
This is my source file.

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Callable;

public class MainClass {

    public static void main(String[] args) {
        try (ExecutorService executor = Executors.newVirtualThreadExecutor()) {
            executor.submit(() -> foo());
            executor.submit(() -> bar());
        }
    }

    static void foo() {
        try (ExecutorService executor = Executors.newVirtualThreadExecutor()) {
            Callable<String> callableTask = () -> {
                //TimeUnit.MILLISECONDS.sleep(300);
                return "Task's execution 1";
            };
            executor.submit(callableTask);
        }
    }

    static void bar() {
        try (ExecutorService executor = Executors.newVirtualThreadExecutor()) {
            Callable<String> callableTask = () -> {
              //  TimeUnit.MILLISECONDS.sleep(300);
                return "Task's execution 2";
            };
            executor.submit(callableTask);
        }

    }
}


I am executing this code in the IntelliJ.

Project SDK is set to java 16.
Project language level is set to x-experimental features as 16 was not
available.

I am able to resolve the project. But when I try to execute the code I got
the following error.



*Error:(8, 50) java: cannot find symbol  symbol:   method
newVirtualThreadExecutor()  location: class java.util.concurrent.Executors*

Please tell me where I am wrong.
-- 
Thanks and Regards

*Priyanka Thakur*
Software Consultant
Knoldus Inc. <http://www.knoldus.com/>
+91-9911676745
Canada - USA - India - Singapore
<https://in.linkedin.com/company/knoldus> <https://twitter.com/Knolspeak>
<https://www.facebook.com/KnoldusSoftware/> <https://blog.knoldus.com/>

-- 
Your feedback matters - At Knoldus we aim to be very professional in our 
quality of work, commitment to results, and proactive communication. If you 
feel otherwise please share your feedback 
<https://forms.gle/Ax1Te1DDpirAQuQ8A> and we would work on it. 


More information about the loom-dev mailing list