Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - Cannot Find symbol class concurrent

I have the following Java class:

import java.util.concurrent;

public class Test{


    public static void main(String[] args){
            ExecutorService ex = Executors.newCachedThreadPool();

            for(int i=0; i<10; i++){
                    ex.execute(new PeerThread(i+1));
            }


    }

}

For some reason, .concurrent does not import correctly. Instead, it gives me the error:

import java.util.concurrent;
            ^
symbol:   class concurrent
location: package java.util

Of course, it also gives me an error related to the usage of Executor, but that is to be expected if it can't find the concurrent package.

I downloaded the latest version of the SDK as well as the latest version of regular Java (as I was unsure whether or not this mattered).

java -version reports java 1.7.0_51.

http://www.java.com/en/download/installed.jsp reports Java 7 51 as well.

If it matters, I am running Mac OSX 10.9.1.

I'm sure it is something stupid.

Thanks in advance.

like image 377
cobrabb Avatar asked Oct 15 '25 11:10

cobrabb


2 Answers

You just forgot the star to import all classes in the package java.util.concurrent.

import java.util.concurrent.*;

Otherwise it thinks concurrent is a class to be imported from java.util, and of course it does not exist.

like image 129
rgettman Avatar answered Oct 18 '25 02:10

rgettman


java.util.concurrent is a package not Class.So use Specific class name to import from this package or else use *.
For example
use import java.util.concurrent.AbstractExecutorService;
or
import java.util.concurrent.*;

like image 41
Prabhaker A Avatar answered Oct 18 '25 03:10

Prabhaker A



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!