Cannot import java.util.concurrent.locks ... WHY?
Why is Xcode unable to find the java.util.concurrent.locks package. The class browser knows it exists. For example the entry for the ReentrantLock class looks like this in the browser class window:
ReentrantLock (java.util.concurrent.locks)
Xcode knows about other java.util packages such as java.util.ResourceBundle which I have been accessed successfully in other parts of my projecgt.
Here is a source file and the resulting compiler error:
The source file:
// Foo.java
import java.util.ResourceBundle;
import java.util.concurrent.locks;
public class Foo { }
The compiler error:
compile:
Compiling 2 source files to /Users/Terry/Desktop/JAVA/PROJECTS/Logic/bin
/Users/Terry/Desktop/JAVA/PROJECTS/Logic/src/Foo.java:3: cannot find symbol
symbol : class locks
location: package java.util.concurrent
import java.util.concurrent.locks;
^
1 error
BUILD FAILED
Help or hints would be greatly appreciated!
Well the reason to your problem is very simple... java.util.concurrent.locks is a package... Not a class.
if you want to import a specific class, the class should be written at the end like you did for import java.util.ResourceBundle; but if you want to import a whole package you need to add the little star at the end :
import java.util.concurrent.locks.*;
Or else, you only import the class you need :
import java.util.concurrent.locks.ReentrantLock;
Similar Messages
-
A problem with importing java.util.concurrent
I am rather new to Java with not that much experience. I apologize ahead though if this is the inappropriate forum to post this problem and/or this question has been answered somewhere else (I couldn't find a post on this subject).
Some of my research has lead to using a semaphore if you wish to use the synchronized() method. I looked up that the import for that is under java.util.concurrent.Semaphore; however, thanks to netbeans for pointing this out before I compiled it, this doesn't seem to exist.
I'm using Java version 1.6.0_03 which does seem to be the latest version. Was it simply removed or am I seriously missing something big here? Anyways, I'm at a total loss and hopefully someone can point me in the right direction.
Thank you in advance for your help.jiju wrote:
check whether import java.util.concurrent.*; is workingAwesome.
As for netbeans, I went and double checked to see if it is reading from the most updated folder of Java and it is.
So as I said, I am totally lost as to why it's not working. Should I just downgrade to a lower version of Java? Although it would seem kinda weird to do something like this. -
Hi,
In my program I hava inported the java package like
import java.util.*;
import java.sql.*;
import java.text.*;
then for using some classes like Gregorial calender,Date etc,I have to again import
import java.util.Date;
import java.sql.PreparedStatement;
import java.util.GregorianCalendar;
As far as I know if I have import the above like
import java.util.*; then it means I can use any classes in java.util ,but if I am not importing
import java.util.GregorianCalendar;
import java.util.Date;
my program is giving error.Can somebody tell me,where my concept is wrong.
Thanksimport java.sql.*;
import java.util.*;
//import java.util.Date; // <-- needed to avoid "the type Date is ambiguous"
public class PackageEg {
public static void main(String[] args) {
Date test = new Date();
}This code gives an error when I compile it, but if I include the
java.util.Date import it is good. The reason is that there are two
possible Date classes - one in java.util and one in java.sql. The
compiler cannot figure out which one I mean.
If I include a specific class like java.util.Date, then this one will be used
in preference to any .* imports. (These are called "imports on demand")
This explains why you need java.util.Date, but the other two are a
mystery. As far as I know PreparedStatement and GregorianCalander
are unique names within the packages you mention. Could you post
some code that will not compile unless the specific import statements
are there? -
Java.util.concurrency.Lock versus synchronized()
Which method is more efficient? or are they both equally efficient for different uses?
Thanks,
Gilidid you read the doc?
For me it was the first time and I just glanced over it, but two nice features stick out:
1) whereas a synchronized method will block a thread until the existing thread has left, a thread attempting to acquire a lock could wisely decide to try again later by checking the lock
2) the ReadWriteLock sub-interface of Lock allows an exclusive many-readers orone-writer access which cannot be acheived through basic method serialization -
Java.util.concurrent.locks.Condition question
Hi all,
what is in practice the difference between condition.await() and
condition.awaitUninterruptibly()?
Why should I permit to wake up a dormant thread if the condition doesn't hold?
What is the "best" solution?
Regards,
MicheleHi all,
what is in practice the difference between condition.await() and
condition.awaitUninterruptibly()?
Why should I permit to wake up a dormant thread if the condition doesn't hold?
What is the "best" solution?
Regards,
Michele -
Java.util.concurrent.LinkedBlockingDeque: cannot find symbol
Hello,
I'm trying to use an existing java code into a JavaFX application. To do this, I copied all my sources into the fx project in Netbeans and I linked the needed libraries, but when I tried to compile all this, I got the following message:
"cannot find symbol
symbol : class LinkedBlockingDeque
location: package java.util.concurrent
import java.util.concurrent.LinkedBlockingDeque;"
the problem is at that line: import java.util.concurrent.LinkedBlockingDeque;
This is a native java class. Is it not supported in JavaFx? Is not java fully compatible with Fx? What's happening?
Thank you in advancePlease, create an issue on it with the detailed comments: [http://www.netbeans.org/issues/enter_bug.cgi?component=javafx|http://www.netbeans.org/issues/enter_bug.cgi?component=javafx]
-
Supplementing java.util.concurrent.TimeUnit with a Duration?
Ever since the concurrency classes were introduced in Java 5 have I been wondering why they designed all the interfaces so clumsily with regards to specifying durations:
every method that expects an amount of time needs 2 parameters, one for the value and one for the unit. IMHO that should have been just one value-object!
So in my projects I'm using a class called "Duration" that encapsulates a long value together with a TimeUnit. http://www.neppert.com/duration/doc/index.html
It has turned out to be extremely handy, because it adheres to the DRY rule: only once, usually when reading timeouts from UIs or properties files into Durations do I need to consider the value's unit.
Now when a user tells me "I don't want to type in stupid milliseconds, I want minutes", it's just one place I have to change ;-)
Would it be good to have such a class in the JDK?jiju wrote:
check whether import java.util.concurrent.*; is workingAwesome.
As for netbeans, I went and double checked to see if it is reading from the most updated folder of Java and it is.
So as I said, I am totally lost as to why it's not working. Should I just downgrade to a lower version of Java? Although it would seem kinda weird to do something like this. -
Java.util.concurrent.*;
i am comming up with this error when i compile my code "package java.util.concurrent does not exist"
i have the code
import java.util.concurrent.*;
and i have just updated my java java SE 6 update 5.
i am using netbeans 3.6.
does anybody know what my problem is???????Ouch, is there a reason why you're still using Netbeans 3.6 instead of something a little more recent? The newer versions are much improved.
It's been a very long time since I used 3.6, but I seem to recall that you can change the JDK used by 3.6 by changing one of the configuration files. Should be something like $NETBEANS_HOME/etc/netbeans.conf. In that file should be a jdkhome variable. -
I am trying to do the sample contact walkthrough in FLEX
builder. For the Java Adapter.
http://livedocs.macromedia.com/flex/2/docs/wwhelp/wwhimpl/js/html/wwhelp.htm?href=00000138 .html
I cannot get any import statements to work for the java class
files. I have tried this using the FDS as a J2EE application
running in tomcat, I have tried with the standalone JRUN version of
the FDS app.
I have put the contact files everywhere I can think of, in
the server classes folder, in the project, in the default web
folder and nothing I try works. I have even setup the project to
compile on the server and I get nothing. Everytime, I get errors.
I did the tutorial from the JDJ magazine:
http://java.sys-con.com/read/210991.htm
I cant get that java connection to work either. Please
someone help me.
The flex code is below.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Script>
<![CDATA[
import mx.data.DataService;
import mx.collections.ArrayCollection;
import samples.contact.Contact;
public var ds:DataService;
[Bindable]
public var contacts:ArrayCollection;
//public var contact:Contact;
]]>
</mx:Script>
<mx:DataGrid id="dg" editable="true">
<mx:columns>
<mx:DataGridColumn dataField="contactId" headerText="Id"
editable="false"/>
<mx:DataGridColumn dataField="firstName"
headerText="First Name"/>
<mx:DataGridColumn dataField="lastName" headerText="Last
Name"/>
</mx:columns>
</mx:DataGrid>
</mx:Application>Ken, thank you for replying, I have had absolutly nothing but
problems trying to get this 'simple' thing to work.
Here is my code.
In the remote-config.xml file, I have this code:
<?xml version="1.0" encoding="UTF-8"?>
<service id="remoting-service"
class="flex.messaging.services.RemotingService"
messageTypes="flex.messaging.messages.RemotingMessage">
<adapters>
<adapter-definition id="java-object"
class="flex.messaging.services.remoting.adapters.JavaAdapter"
default="true"/>
</adapters>
<default-channels>
<channel ref="my-amf"/>
</default-channels>
<destination id="SimpleJava">
<properties>
<source>javaSamples.SimpleMath</source>
</properties>
</destination>
</service>
Here is my MXML file: (Called new.MXML)
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:RemoteObject id="math" destination="SimpleJava">
<mx:method name="doMath" concurrency="last"
result="fillTxt(event.result as int)"/>
</mx:RemoteObject>
<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent
private function fillTxt(b: int):void{
txtResult.text = (String)
//comment
]]>
</mx:Script>
<mx:Panel x="10" y="24" width="250" height="200"
layout="absolute" title="Simple Math with Java">
<mx:Label x="10" y="10" text="Input Number to
Multiply:"/>
<mx:TextInput x="10" y="36" id="txtNumber"
maxChars="1"/>
<mx:Label x="10" y="126" id="txtResult"/>
<mx:Label x="10" y="100" text="Your Number will appear
below:"/>
<mx:Button x="10" y="66" label="Multiply by 2"
click="math.doMath(txtNumber.text)"/>
</mx:Panel>
</mx:Application>
Here is my SimpleJava.java file:
package javaSamples;
//import java.util.*;
* @author jsanders
public class SimpleMath {
public int doMath(String a){
int new_a = Integer.parseInt(a.trim());
int b = new_a * 2;
return b;
//changesd
Like I said I have had absolutly nothing but problems with
this. Yesterday, I was getting send failures, So I did some
reasearch found some folks who said that they had the same problem,
and they had to hard code the app name into the services-config.xml
file. The file used to have {context.root} in it, and that variable
was set to /flex, now I hardcoded this line into the my-amf channel
definition to get rid of the send failure error.
<channel-definition id="my-amf"
class="mx.messaging.channels.AMFChannel">
<endpoint uri="
http://{server.name}:{server.port}/flex/messagebroker/amf"
class="flex.messaging.endpoints.AMFEndpoint"/>
<properties>
<polling-enabled>false</polling-enabled>
</properties>
</channel-definition>
As you can see what should say:
http://{server.name}:{server.port}/{context.root}
Now says:
http://{server.name}:{server.port}/flex.
This was the only way I could get the send error to go away.
Now I worry that I might have broken something else. Since I
removed all references to {context.root} in that file.
{context.root} is defined in the flex-config.xml file, like
this:
<context-root>/flex</context-root>
I have tried it with or without the '/' in the value of the
context.root variable.
I have played with the remoting-config file, and I know that
I am accessing the destination.
I have played with the <source> option of the
destination, and I know that I am finding the class and making a
good connection.
I am using the JRUN install of FDS on my box, and yesterday
at the end of the day after getting the context.root situation
sorted out, I got a different error something like major.minor
versioning errors.
So the Java guys here at work told me that the JRUN version
packaged with FDS was 1.4, and I used 1.5 to compile my java class.
So I recompiled this morning with the 1.4 sdk. Now I dont get that
error about the major minor versioning anymore.
Now I get nothing. I use firefox, and all the browser tells
me is 'transferring data from localhost' Nothing else. It just sits
there and does nothing.
When I did the debug on it, I got into a loop on the
UIComponent.as file in the callLaterDispatcher(event:Event)
function.
Any clues what might be causing this new hang up. Basically
the machine just hangs. Is there a problem with the result from the
Method I am calling in the MXML? Did I do something wrong with the
Event as Int thing?
Again any help would be appreciated. -
Java.util.concurrent.ConcurrentHashMap
All,
I prefer to use the java.util.ConcurrentHashMap over a Hashtable but there are some points regarding this structure that are not very clear to me.
From java.util.concurrent: Class ConcurrentHashMap:
"A hash table supporting full concurrency of retrievals and adjustable expected concurrency for updates. This class obeys the same functional specification as Hashtable, and includes versions of methods corresponding to each method of Hashtable.
*+However, even though all operations are thread-safe, retrieval operations do not entail locking, and there is not any support for locking the entire table in a way that prevents all access. This class is fully interoperable with Hashtable in programs that rely on its thread safety but not on its synchronization details. Iterators are designed to be used by only one thread at a time."+ *
Also from: Java API: Package java.util.concurrent, we read:
"The "Concurrent" prefix used with some classes in this package is a shorthand indicating several differences from similar "synchronized" classes. For example java.util.Hashtable and Collections.synchronizedMap(new HashMap()) are synchronized. But ConcurrentHashMap is "concurrent". A concurrent collection is thread-safe, but not governed by a single exclusion lock. In the particular case of ConcurrentHashMap, it safely permits any number of concurrent reads as well as a tunable number of concurrent writes. "Synchronized" classes can be useful when you need to prevent all access to a collection via a single lock, at the expense of poorer scalability. In other cases in which multiple threads are expected to access a common collection, "concurrent" versions are normally preferable. And unsynchronized collections are preferable when either collections are unshared, or are accessible only when holding other locks."
Based on above, is this correct of I say:
When using a structure like Hashtable, all the methods or operations are synchronized,
meaning if one thread is accessing the Hashtable (by get(), put(),... or other methods on this structure), it owns the lock and all other threads will lock out until the thread that owns the lock releases the lock; which means only one thread can access the hash table at a time; which can cause performance issues.
We need to use a synchronized block or method only of two threads modify a "shared resource", if they do not modify a shared resource, we do not need to use the synchronization.
On the other hand, the methods of ConcurrentHashMap are not synchronized; so multiple threads can access the ConcurrentHashMap at the same time. But isn't the ConcurrentHashMap itself the "shared resource" that threads are accessing? Should we use it only if the threads are reading from map and not writing to it? And then if threads also write to the structure, then it looks like its better to not to use the ConcurrentHashMap, rather use the regular HashMap with the synchronized wrapper?
Any help is greatly appreciated.We need to use a synchronized block or method only of two threads modify a "shared resource", if they do not modify a shared resource, we do not need to use the synchronization. Actually, you need to synchronize access to the shared resource for both readers and writers. If one thread is updating an unsynchronized HashMap, and a concurrent thread tries to read that map, it may be in an inconsistent state. When synchronizing on the map, the reader will be blocked until the writer completes.
What you don't need to do is prevent multiple readers from accessing the map, if there's no writer. However, a synchronized map or HashTable will single-thread reads as well as writes.
On the other hand, the methods of ConcurrentHashMap are not synchronized; so multiple threads can access the ConcurrentHashMap at the same time. But isn't the ConcurrentHashMap itself the "shared resource" that threads are accessing? No, it's actually synchronized at a finer level. Without getting into the details of HashMap implementation, an object's hashcode is used to identify a linked list of hashmap entries. The only time that you have a concurrency issue is when a reader and writer are accessing the same list. So the ConcurrentHashMap locks only the list that's being updated, and allows readers (and writers!) to access the other bucket lists. Plus, it allows two readers to proceed concurrently. -
How come program wont accept import java.util ?
I get cannot resole symbol ?? i looked in up in my java book and its spelled right . what gives ?there is no class named java.util .
import java.util.ArrayList;
import java.util.EventObject;
or
import java.util.*; -
Compile error import java.util.map$entry
Hi,
I am trying to compile code which imports the following package
import java.util.Map$Entry.
The error thrown up is : cant resolve symbol Map$Entry. Why is there a $ in the package import path and is there some configuration required to compile the file.
I am not allowed to change the code. Does anyone have an idea on how this problem can be solved.
Thanks and regards
Kumar VellalBtw java docs for the interface are available at:
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Map.Entry.html
Changing the import should probably help compile the code, but without changing the import .. need to check. This is just from what i remember now. Lets see if anyone else comments on this. -
Error when importing java.util.Scanner
Agh! I'm in an introduction to computer science course, and I am writing a program as an assignment that's due tomorrow.
I have imported java.util.Scanner before, but I've only run it on the Windows PCs in the lab, whereas I am currently on a Mac. I've updated to the latest version of Java (through the software update), and I'm running Tiger (also fully updated).
I'm using Dr. Java to write the programs, but I tried using the very same thing in Eclipse and it didn't work. Here's my program:
import java.util.Random;
import java.util.Scanner;
public class Password {
public static void main(String[] args) {
//create a Scanner object to read from the keyboard:
String password;
Scanner scanner = new Scanner(System.in);
Random randomizer = new Random();
System.out.println("Please enter a string containing candidate characters.");
String input = scanner.next();
int charLength = length(input);
System.out.print("Random password: ");
System.out.print(input.substring(randomizer.nextInt(charLength)));
System.out.print(input.substring(randomizer.nextInt(charLength)));
System.out.print(input.substring(randomizer.nextInt(charLength)));
System.out.println(input.substring(randomizer.nextInt(charLength)));
And, here's my errors:
4 errors found:
File: /Users/brianmoore/Desktop/Password.java [line: 11]
Error: cannot resolve symbol
symbol : class Scanner
location: package util
File: /Users/brianmoore/Desktop/Password.java [line: 18]
Error: cannot resolve symbol
symbol : class Scanner
location: class Password
File: /Users/brianmoore/Desktop/Password.java [line: 18]
Error: cannot resolve symbol
symbol : class Scanner
location: class Password
File: /Users/brianmoore/Desktop/Password.java [line: 22]
Error: cannot resolve symbol
symbol : method length (java.lang.String)
location: class Password
Any ideas?Ok. I figured it out. On the Dr. Java page, this is what helped me:
Please verify the following:
- Open "/Applications/Utilities/Java/J2SE 5.0/Java
Preferences";
make sure "J2SE 5.0" is at the top of the list under
"Java
Application Runtime"
- Open DrJava; go to Edit->Preferences; make sure
"Tools.jar
Location", "JSR-14 Location", and "JSR-14
Collections Path"
are all blank
- Open the Help->About dialog box; make sure the "DrJava
Version" listed is 20050601-0007 or later (that is, later
than
June 1, 2005)
- Go to the "System Properties" tab in the
"About" box; make
sure "java.version" is 1.4.2.
Let us know what you find out if you're still having
trouble.
Thanks for your help! -
Import java.util.Enumeration;
Hi, I test a programmer under eclipe
I can import java.util.Enumeration;(error on Enumeration)
and Vector connections = null;
Enumeration enum = connections.elements();
while (enum.hasMoreElements())
do something
I got error Enumeration can't not be resolve/
why?
and how to modify to change it?Hi, I test a programmer under eclipe Maybe should test the program, not the programmer ;-)
-
By benefit I mean does it reduce compile time or have some other beneficial side effect to import only those classes you're using in a class rather than importing the package they reside in.
For example:
// this?
import java.util.Vector;
// or this..
import java.util.*;
class Test
Vector v;
}Question is strictly academic...I'm just curious.I like Dr. clap's answer. Also, though you can
consider code readability. Obviously importing a
whole package doesn't give you an idea of what classes
are being used. "I", personally, have only seen exact
class imports done when learning something new. This
is basically just for clarity, and not speed as Dr.
Clap pointed out.That's probably a good thing to do for examples, but I can't see why you would want to know what individual classes are being used otherwise.
From a programming standpoint if you're going to build a complex dialog you don't want 500 import statements. If you know you're going to be using lots of classes from an individual package might as well import the whole thing.
Maybe you are looking for
-
Can I install a Mac os on windows using bootcamp?
I want to Install Lion onto my dell Laptop so I can run Disk utility and clone my mac hard drive. My problem is my mac was saying i was running out of space on my start up drive for a lil while now ...then yesterday it said my start up disk is full.
-
In Tools:Options:Languages, does the language on a page have preference?
The Pop-Up Window is not clear about this, and assumes I already know the answer.
-
Mac Office and Microsoft Office 2007
How do you open the Microsoft Office 2007 .docx in Office 2004 for Mac (Professional edition)?
-
Rotate symbol based on cursor angle
Hey There, I am trying to get a symbol to rotate and follow based on the cursor angle and I am running into an issue I can't track down. I am using sym. to decalre my variables so that I can reference them globally whithin my composition. But it look
-
Hi all, i have a requirement to send the inbound payload in the mail content when any error occurs in ABAP proxy. How can I achieve this? Thanks