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.
Similar Messages
-
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; -
Problems with importing java.sql.*
Hi.
When I'm compiling the following code I get this message:
SimpeltDatabaseEksempel.java:4: Package java.sql not found in import import java.sql.*
What could be wrong?
/lars
Here is my code:
import java.sql.*;
public class SimpeltDatabaseeksempel
public static void main(String[] arg) throws Exception
// Udskift med din egen databasedriver og -URL
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection forb = DriverManager.getConnection("jdbc:odbc:datakilde1");
Statement stmt = forb.createStatement();
stmt.executeUpdate("create table KUNDER (NAVN varchar(32), KREDIT float)" );
stmt.executeUpdate("insert into KUNDER values('Jacob', -1799)");
stmt.executeUpdate("insert into KUNDER values('Brian', 0)");
}Don't know what to tell you, except that it exists
http://java.sun.com/j2se/1.5.0/docs/api/java/sql/package-summary.html
What version of java are you using? -
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. -
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]
-
Custom tags in jsp - problems with import in java pgm
Hi,
I am new to JSP and am facing some problems.
I am trying to compile the foll. java program and it is giving an error saying 1."Package javax.servlet.jsp does not exist", 2."Package javax.servlet.jsp.tagext does not exist".
I am using 1.j2sdk1.4.1_02, 2.j2sdkee1.3.1,and 3.Tomcat 4.1
My java_home=C:\j2sdk1.4.1_02
j2ee_home=C:\j2sdkee1.3.1
path=%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;c:\j2sdkee1.3.1\bin;c:\j2sdk1.4.1_02\bin;c:\j2sdkee1.3.1\doc\api;c:\jakarta-ant-1.5.1\bin
classpath=c:\j2sdkee1.3.1\bin;c:\j2sdk1.4.1_02\bin;c:\j2sdkee1.3.1\doc\api
can anybody help me with it?
Regards,
newtojsp
import java.io.IOException;
import java.util.Date;
import doc.api.javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
public class TestTag extends TagSupport
public int doStartTag () throws JSPTagException
String dateString = new Date().toString ();
try
JspWriter out = page.context.getOut ();
out.println ("Welcome to the Loan Dept" + " <br>");
out.println ("Today is:" + dateString + "<br>");
return SKIP_BODY;
} catch (IOException ee)
throw JspTagException ("Error Encountered");
public int doEndTag () throws JSPTagException
return EVAL_PAGE;I got the solution for this.
Thanks
Newtojsp -
We sometimes see this failure intermitently when using the FlexUnit Ant task to run tests in a CI environment. The Ant task throws this exception:
java.util.concurrent.ExecutionException: could not close client/server socket
I have seen this for a while now, and still see it with the latest 4.1 RC versions.
Here is the console output seen along with the above exception:
FlexUnit player target: flash
Validating task attributes ...
Generating default values ...
Using default working dir [C:\DJTE\commons.formatter_swc\d3flxcmn32\extracted\Source\Flex]
Using the following settings for the test run:
FLEX_HOME: [C:\dev\vert-d3flxcmn32\302100.41.0.20110323122739_d3flxcmn32]
haltonfailure: [false]
headless: [false]
display: [99]
localTrusted: [true]
player: [flash]
port: [1024]
swf: [C:\DJTE\commons.formatter_swc\d3flxcmn32\extracted\build\commons.formatter.tests.unit.sw f]
timeout: [1800000ms]
toDir: [C:\DJTE\commons.formatter_swc\d3flxcmn32\reports\xml]
Setting up server process ...
Entry [C:\DJTE\commons.formatter_swc\d3flxcmn32\extracted\build] already available in local trust file at [C:\Users\user\AppData\Roaming\Macromedia\Flash Player\#Security\FlashPlayerTrust\flexUnit.cfg].
Executing 'rundll32' with arguments:
'url.dll,FileProtocolHandler'
'C:\DJTE\commons.formatter_swc\d3flxcmn32\extracted\build\commons.formatter.tests.unit.swf '
The ' characters around the executable and arguments are
not part of the command.
Starting server ...
Opening server socket on port [1024].
Waiting for client connection ...
Client connected.
Setting inbound buffer size to [262144] bytes.
Receiving data ...
Sending acknowledgement to player to start sending test data ...
Stopping server ...
End of test data reached, sending acknowledgement to player ...
When the problem occurs, it is not always during the running of any particular test (that I am aware of). Recent runs where this failure was seen had the following number of tests executed (note: the total number that should be run is 45677): 18021, 18, 229.
Here is a "good" run when the problem does not occur:
Setting inbound buffer size to [262144] bytes.
Receiving data ...
Sending acknowledgement to player to start sending test data ...
Stopping server ...
End of test data reached, sending acknowledgement to player ...
Closing client connection ...
Closing server on port [1024] ...
Analyzing reports ...
Suite: com.formatters.help.TestGeographicSiteUrls
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.008 sec
Suite: com.formatters.functionalUnitTest.testCases.TestNumericUDF
Tests run: 13, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.071 sec
Results :
Tests run: 45,677, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 201.186 sec
Has anyone else ran across this problem?
Thanks,
TrevorI am not sure if this information will help everyone, but here goes...
For us, these problems with FlexUnit tests crashing the Flash Player appear to be related to couple of factors. Recently, we moved up from Flex 3.2 to Flex 4.1 as our development baseline. Many people complained that their development environment (Flash Builder, etc.) was much more unstable. Apparently, 4.1 produces SWFs that require more memory to run than 3.2 does? Anyway, we still had Flash Player 10.1 as our runtime baseline. Apparently, that version of the player was not as capable of running larger FlexUnit test SWFs, and would crash (as I posted months earlier). I upgraded to the latest 10.3 standalone player versions, and the crashes have now ceased. It would be nice to know exactly what was causing the crashes, but memory management (or lack of) is my best guess.
So, if you are seeing these issues, try upgrading to the latest Flash Player version.
Regards,
Trevor -
Hi Experts,
as part of my diploma-thesis I have to write a java SAX-Mapping, which mapps the following incoming message:
mt_MappingOUT
set
set_Element_01
set_Element_02
set_Element_03
set_Element_10
to the following outgoinig message:
mt_MappingIN
TABLE
item
item_FIELD_01
item_FIELD_10
I develped the following code, which unfortunately results in "XML is not well defined" while testing. Unfortunately I cannot find the problem. So I hope someone of you can have a look an will have an idea.
Created on 20.12.2007
@author Sebastian Geissler
import java.io.FileInputStream;
import java.io.FileOutputStream;
import com.sap.aii.mapping.api.*;
import java.io.*;
import java.util.Map; import javax.xml.parsers.*;
import org.xml.sax.; import org.xml.sax.helpers.;
public class SETtoITEMjavaSAX extends DefaultHandler implements StreamTransformation
private Map map;
private OutputStream out;
public void setParameter (Map param)
map = param;
public void execute (InputStream in, OutputStream out)
throws com.sap.aii.mapping.api.StreamTransformationException
DefaultHandler handler = this;
SAXParserFactory factory = SAXParserFactory.newInstance();
try
SAXParser saxParser = factory.newSAXParser();
this.out = out; saxParser.parse(in, handler);
catch (Throwable t)
t.printStackTrace();
private void write (String s) throws SAXException
try
out.write(s.getBytes()); out.flush();
catch (IOException e)
throw new SAXException("I/O error", e);
public void startDocument () throws SAXException
write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
write("<ns0:mt_MappingIn xmlns:ns0=\"urn:agrp:xi:geissseb\"><TABLE>");
public void endDocument () throws SAXException
write("</TABLE></ns0:mt_MappingIn>");
try { out.flush();
catch (IOException e) {
throw new SAXException("I/O error", e);
public void startElement (String namespaceURI, String sName, String qName, Attributes attrs)
throws SAXException
String eName = sName;
if ("".equals(eName))
eName = qName;
if(eName.equals("set"))
write("<item>");
if(eName.substring(0,6).equals("set_E"))
write("<item_FIELD"eName.substring(10,13)">");
public void endElement (String namespaceURI, String sName, String qName) throws SAXException
String eName = sName;
if ("".equals(eName))
eName = qName;
if(eName.equals("set"))
write("</item>");
if(eName.substring(0,6).equals("set_E"))
write("</item_FIELD"eName.substring(10,13)">");
public void characters (char buf[], int offset, int len)
throws SAXException {
String s = new String(buf, offset, len);
write (s);
Thank you,
SebastianHi Ravi, hi Raman,
thanks so far... I did some changes in my code, but I am still having the same problem... down there you will find my new code and the source message.
there is my new code:
private Map map;
private OutputStream out;
public void setParameter (Map param)
map = param;
public void execute (InputStream in, OutputStream out)
throws com.sap.aii.mapping.api.StreamTransformationException
DefaultHandler handler = this;
SAXParserFactory factory = SAXParserFactory.newInstance();
try
SAXParser saxParser = factory.newSAXParser();
this.out = out; saxParser.parse(in, handler);
catch (Throwable t)
t.printStackTrace();
private void write (String s) throws SAXException{
try{
out.write(s.getBytes()); out.flush();
catch (IOException e){
throw new SAXException("I/O error", e);
public void startDocument () throws SAXException{
write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
write("<ns0:mt_mappingOUT xmlns:ns0=\"urn:agrp:xi:geissseb\"><TABLE>");
public void endDocument () throws SAXException {
write("</TABLE></ns0:mt_mappingOUT>");
try { out.flush();
catch (IOException e) {
throw new SAXException("I/O error", e);
public void startElement (String namespaceURI, String sName, String qName, Attributes attrs)
throws SAXException {
String eName = sName;
if ("".equals(eName))
eName = qName;
if(eName.equals("mtset"))
write("<item>");
if(eName.substring(0,2).equals("se"))
write("<Item_FIELD_"eName.substring(13,14)">");
public void endElement (String namespaceURI, String sName, String qName) throws SAXException {
String eName = sName;
if ("".equals(eName))
eName = qName;
if(eName.equals("mtset"))
write("</item>");
if(eName.substring(0,2).equals("se"))
write("</item_FIELD_"eName.substring(13,14)">");
public void characters (char buf[], int offset, int len)
throws SAXException {
String s = new String(buf, offset, len);
write (s);
and there is the source message:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:agrp:xi:geissseb" targetNamespace="urn:agrp:xi:geissseb">
<xsd:element name="mt_MappingOut" type="dt_MappingOut" />
<xsd:complexType name="dt_MappingOut">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
4c79fbb0bde711dcae43001a4b0af224
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="set">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
0b366510aeda11dcb3bb00174205b856
</xsd:appinfo>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:element name="set_ELEMENT_01" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
0b366511aeda11dcaf2600174205b856
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="set_ELEMENT_02" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
0b366512aeda11dc84d400174205b856
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="set_ELEMENT_03" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
0b366513aeda11dcbcab00174205b856
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="set_ELEMENT_04" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
0b366514aeda11dc96a300174205b856
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="set_ELEMENT_05" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
0b366515aeda11dca77700174205b856
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="set_ELEMENT_06" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
0b366516aeda11dc8f7d00174205b856
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="set_ELEMENT_07" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
0b366517aeda11dcc24b00174205b856
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="set_ELEMENT_08" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
0b366518aeda11dc92cd00174205b856
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="set_ELEMENT_09" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
0b366519aeda11dcc9b100174205b856
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="set_ELEMENT_10" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="http://sap.com/xi/TextID">
0b36651aaeda11dcc5a700174205b856
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
I really hope you can help me there..
Thanks in advance..
Sebastian -
Using ExecutorService class from java.util.concurrent package
Dear java programmers,
I have a question regarding the ExecutorService class from java.util.concurrent package.
I want to parse hundreds of files and for this purpose I'm implementing a thread pool. The way I use the ExecutorService class is summarized below:
ExecutorService executor = Executors.newFixedThreadPool(10);
for (int i = 0; i < 1000; i++){
System.out.println("Parsing file No "+i);
executor.submit(new Dock(i));
executor.shutdown();
try {
executor.awaitTermination(30, TimeUnit.SECONDS);
} catch (InterruptedException ex) {
ex.printStackTrace();
executor.shutdownNow();However, the code snippet above creates all the 1000 threads (Dock objects) at once and loads them to the executor, and thus I'm worrying about memory leak. I haven't tested it on 1000 files yet but just on 50 small ones, and even if the program prints out "Parsing file No "+i 50 times at once, it executes normally the threads in the background.
I guess the write way would be to keep the number of active/idle threads in the executor constant (lets say 20 if the thread pool's size is 10) and submit a new one whenever a thread has been finished or terminated. But for this to happen the program should be notified someway whenever a thread is done. Can anybody help me do that?
thanks in advance,
TomOk I found a feasible solution myself although I'm not sure if this is the optimum.
Here's what I did:
ExecutorService executor = Executors.newFixedThreadPool(10);
Future<String> future0, future1, future2, future3, future4, future5, future6, future7, future8, future9;
Future[] futureArray = {future0 = null, future1 = null, future2 = null, future3 = null, future4 = null, future5 = null,
future6 = null, future7 = null, future8 = null, future9 = null};
for (int i = 0; i < 10; i++){
futureArray[i] = executor.submit(new Dock(i));
}I created the ExecutorService object which encapsulates the thread pool and then created 10 Future objects (java.util.concurrent.Future) and added them into an Array.
For java.util.concurrent.Future and Callable Interface usage refer to:
[http://www.swingwiki.org/best:use_worker_thread_for_long_operations]
[http://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Java/Chapter10/concurrencyTools.html]
I used a Future[] Array to make the code neater. So after that I submitted -and in this way filled up- the first 10 threads to the thread pool.
int i = 9;
while (i < 1000){
for (int j = 0; j < 10; j++){
if (futureArray[j].isDone() && i < 999){
try{
i++;
futureArray[j] = executor.submit(new Dock(i));
} catch (ExecutionException ex) {
ex.printStackTrace();
} catch (InterruptedException ex) {
ex.printStackTrace();
try {
Thread.sleep(100); // wait a while
} catch(InterruptedException iex) { /* ignore */ }
executor.shutdown();
try {
executor.awaitTermination(60, TimeUnit.SECONDS);
} catch (InterruptedException ex) {
ex.printStackTrace();
executor.shutdownNow();
}Each of the future[0-9] objects represents a thread in the thread pool. So essentially I'm check which of these 10 threads has been finished (using the java.util.concurrent.Future.isDone() method) and if yes I replenish that empty future[0-9] object with a new one. -
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. -
Java.util.concurrent.ExecutorService inside J2EE Container
I want to use the JDK 1.5 concurrency class ExecutorService for concurrent execution of data-access logic inside my oc4j web-application.
I'm using the Factory Executors.newFixedThreadPool(6) for creating a thread-pool.
I know that it's not a good practice to create new threads inside a j2ee container.
Is there anything I have to think of or beware of??
Perhaps anybody here has experience using the java.util.concurrent.Executor inside OC4J or an other j2ee container.
Thanks, HaraldYes, I have used java.util.concurrent.Executor in weblogic 10 server.
You can really improve the performance of the EJB application if you use the thread pool carefully with limited size say 100 threads, by creating a single instance of thread pool for the whole J2EE application.
You have to control the life cycle of thread pool using the container's life cycle methods, create the thread pool only once and destroy every time you recycle your app.
Good luck with the implementation :) -
Java.util.concurrent.ExecutorService inside OC4J
I want to use the JDK 1.5 concurrency class ExecutorService for concurrent execution of data-access logic inside my oc4j web-application. I'm using the Factory Executors.newFixedThreadPool(6) for creating a thread-pool.
I know that it's not a good practice to create new threads inside a j2ee container.
Is there anything I have to think of or beware of??
Perhaps anybody here has experience using the java.util.concurrent.Executor inside OC4J.
Thanks, HaraldYes, I have used java.util.concurrent.Executor in weblogic 10 server.
You can really improve the performance of the EJB application if you use the thread pool carefully with limited size say 100 threads, by creating a single instance of thread pool for the whole J2EE application.
You have to control the life cycle of thread pool using the container's life cycle methods, create the thread pool only once and destroy every time you recycle your app.
Good luck with the implementation :) -
Problem with Importing Packages
I have a file which has several classes and an interface. The first line is package ImageSequence; . It is saved in a file called ImageSequence.java. I have another file in the same directory that has include ImageSequence.* as the third line. I get an error that the package is not found. What is wrong?
Thanks, but that still doesn't solve the problem. I have this code:
import java.awt.*;
import javax.swing.*;
import java.util.*;
import ImageSequence.*;
public class ImageSequenceTest extends JComponent {
public static void main(String args[])
new ImageSequenceTest();
public ImageSequenceTest()
Toolkit toolkit = Toolkit.getDefaultToolkit();
Image i1 = toolkit.getImage("ImageSequenceTesti1.gif");
Image i2 = toolkit.getImage("ImageSequenceTesti2.gif");
Image i3 = toolkit.getImage("ImageSequenceTesti3.gif");
Image i4 = toolkit.getImage("ImageSequenceTesti4.gif");
Image i5 = toolkit.getImage("ImageSequenceTesti5.gif");
Image i6 = toolkit.getImage("ImageSequenceTesti6.gif");
Image images[] = new Image[] {i1, i2, i3, i4, i5, i6};
ImageSequence is = new ImageSequence(images, 50);
JFrame frame = new JFrame();
frame.setSize(100, 100);
frame.getContentPane().add(is);
frame.setVisible(true);
is.setRepeat(true);
is.start();
}When I try to compile it, I get these error messages:C:\Program Files\Xinox Software\JCreator LE\MyProjects\ImageSequenceTest.java:22: cannot resolve symbol
symbol : constructor ImageSequence (java.awt.Image[],int)
location: class ImageSequence
ImageSequence is = new ImageSequence(images, 50);
^
C:\Program Files\Xinox Software\JCreator LE\MyProjects\ImageSequenceTest.java:25: cannot resolve symbol
symbol : method add (ImageSequence)
location: class java.awt.Container
frame.getContentPane().add(is);
^
C:\Program Files\Xinox Software\JCreator LE\MyProjects\ImageSequenceTest.java:27: cannot resolve symbol
symbol : method setRepeat (boolean)
location: class ImageSequence
is.setRepeat(true);
^
C:\Program Files\Xinox Software\JCreator LE\MyProjects\ImageSequenceTest.java:28: cannot resolve symbol
symbol : method start ()
location: class ImageSequence
is.start();
^
4 errors
When I get rid of import ImageSequence.*; and copy the code for the ImageSequence class from the package into the file, everything works. -
Problem with "import sabasrv.database.*;"
Hi there..
I am new to the Java game so this is probably a very easy problem to fix.
I am using the Forte IDE and My code has the following imports :
package sabasrv.user;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.lang.*;
import java.sql.SQLException ;
import sabasrv.database.*;
The problem is that whenI try to compile I get the following error:
src/sabasrv/user/User.java [8:1] Package sabasrv.database. not found in import.
import sabasrv.database.*;
^
src/sabasrv/user/User.java [16:1] Class DbSql not found in type declaration or import.
DbSql sql ;
^
2 errors
Any ideas why I am getting this? My CLASSPATH environment variable is :
CLASSPATH=C:\jdk1.1.8\jsdk23.jar;C:\old_Saba_servlet\src\sabasrv\database
I hope this is enough info to go on.
Your fwend.
KorwinYou classpath should probably be
C:\old_Saba_servlet\src
instead of
C:\old_Saba_servlet\src\sabasrv\database
if you have classfiles in that directory and not just the source files. Try that. The package name is "appended" to the classpath, so sabasrv.user will be /sabasrv/user when it looks for class files in that package.
Maybe you are looking for
-
Error while creating Data Form Definition report from Planning
Hi All, Working on Planning 11.1.2 (x64) I tried to generate a Data Form Definition report from Planning and found that I get an error if I select the option "Include member selection list". By going a bit deeper, I realised that it errors for some f
-
Travel Expense Manager (PR05): Trigger "Add Data Maintain:Status" upon SAVE
Hi TM Gurus, Good day. The "Add Data Maintain: Status" Screen can be manually accessed by clicking the "Trip Status" Button in PR05. Can you kindly confirm if it's possible to automatically trigger the "Add Data Maintain:Status" Screen via configura
-
Transferring Photoshop CS6 from PC to Mac
Hi, I bought Photoshop CS6 earlier in the year to put on my aging PC. However, since buying it, my PC has developed an problem which prevents me from connecting to the internet. I subsequently have yet to install or register my copy of Photoshop. I a
-
I just updatet my Iphone 4S to IOS6 and the where a error, and now itunes telling me I need to recover my Iphone to use my Iphone and to recover I will lose all my media files and other files! this is an disaster! What can I do? EVEN MY IPHONE DON'T
-
any help cant sign into itunes or downloads any apps