| When to synchronize a list |
|
 |
Index ‹ java-programmer
|
- Previous
- 1
- 3
- Multiline Textbox For Web pageHello,
I have been trying to get a textbox to work now for over a week, and
am starting to think there is not answer. I have a web application
that populates an htmlinputtextarea. The reason I chose it was
because it could display multiple lines. However, if the report gets
too wide for the textbox, the text starts to wrap. I have tried
override and white-space for CSS class, but the best I can get is one
long line (white-space: nowrap). For the setValue, I use \r\n for my
end of line. Example: txtBox.setValue("This is one line\r\nThis is
line two.");
Is there a better textbox than the htmlinputtextarea to display
multiple lines of text with a vertical and horizontal scrollbar? If
not anybody know what I am doing wrong?
Thanks for any help
Ryan
- 3
- newbie to javahello,
In following code there is a abstract class so i am not allowed to
create instance of class.
so Figure f = new Figure(10, 10); is wrong but why following statement
is valid?
Figure figref;
CLASS CODE =>
abstract class Figure {
double dim1;
double dim2;
Figure(double a, double b) {
dim1 = a;
dim2 = b;
}
abstract double area();
}
- 3
- searching for encrypted fields in data columnsI am new to database programming and was curious how others solve the
problem of storing encrypted in data in db table columns and then
subsequently searching for these records.
The particular problem that I am facing is in dealing with (privacy)
critical information like credit-card #s and SSNs or business critical
information like sales opportunity size or revenue in the database. The
requirement is that this data be stored encrypted (and not in the
clear). Just limiting access to tables with this data isn't sufficient.
Does any database provide native facilities to store specific columns as
encrypted data ? The other option I have is to use something like RC4 to
encrypt the data before storing them in the database.
However, the subsequent problem is how do I search/sort on these columns
? Its not a big deal if I have a few hundred records; I could
potentially retrieve all the records, decrypt the specific fields and
then do in process searches/sorts. But what happens when I have (say) a
million records - I really don't want to suck in all that data and work
on it but instead use the native db search/sort capabilities.
Any suggestions and past experiences would be greatly appreciated.
much thanks,
~s
- 4
- Images from Jar Files? - How do YOU do it?
It occurs to me that this may be the best way to approach this situation:
If you have a stand-alone java application that runs from a JAR file,
and you have images contained in that JAR file that your application
loads... how do YOU do it?
I'm specifically interested in Jar Bundled applications for OSX, but any
code will do.
If anyone could provide sample code, it would be very much appreciated!
CT
- 5
- Instantiating a class read in from user inputI am trying to write a simple application that will instantiate a class
whose name is read in from user input. Since the name of the class is being
read in as a String, how can it be instantiated? For example, suppose I
store the name of the user supplied class in a String variable called
ClassName. I can't simple just instantiate the class with a statement such
as new ClassName(), since ClassName is a String. Any advice?
- 6
- pico, nano, micro and JavaFirst off, this is for a school assignment... I know some people get
squeamish about this sort of post, but I'm kind of up a creek.
Basically, as part of a semester-long project, we need to add another bean
to a program we've been working on, and integrate it with the rest of the
program. That part's not the issue.
Part of the specification for the bean states tnat the user must be able to
select (and optionally enter) values ranging from 100 picofarads up to 1
microfarad. That's 1 * 10^-10 up to 1 * 10^-6, and everything in between.
Now... For ease of use purposes, the input is supposed to involve something
like a combobox or a spinner or a slider, or something like that, with
clearly delineated default values, which the user can then customise.
So, for testing purposes, I have a combobox containing the numbers 1 to 10,
and a second combobox that allows you to select your unit (pF, nF, uF).
So... In an attempt to get this post over with... Does Java include a
quick and easy way of taking an entry like "250 nF" and converting it to
2.5*10^-7 for calculation purposes? I was thinking of putting the whole
thing into a switch based on the contents of the units box (or possibly a
bunch of if statements), but then there's the problem of a certain amount of
variation in the multipliers used depending on the actual number entered.
Does any of this make sense?
- 7
- trying to extend messageresources classhi..
i'm trying to create my own messageresources class and placed:
<init-param>
<param-name>application</param-name>
<param-value>coreservlets.Messages</param-value>
</init-param>
<init-param>
<param-name>factory</param-name>
<param-value>coreservlets.MessageFactory</param-value>
</init-param>
in the web.xml file of the context, but struts, ignores it and keeps
using it's own.
- 7
- Creating EJB Instance on server startupHi,
I programmed a stateless SessionBean that acts as a timer service
(implements TimeObject). Since this timer service should be available
after the server has started, I am looking for a way to realize this. I
thought about creating a pool, where at least one instance is residing
in so I configured in my jboss.xml:
<container-configuration extends="Standard Stateless SessionBean">
<container-name>Pooled Stateless SessionBean</container-name>
<instance-pool>org.jboss.ejb.plugins.StatelessSessionInstancePool</instance-pool>
<container-pool-conf>
<MinimumSize>1</MinimumSize>
<MaximumSize>1</MaximumSize>
<strictMaximumSize>1</strictMaximumSize>
</container-pool-conf>
</container-configuration>
But this doesn't bring the expected result. I realized, that the
ejbCreate method of my session bean is called as recently as I am
calling a custom method of my remote interface. So my container isn't
creating any bean instance at all at the startup. What can I do now ?
Thanx,
Phil.
- 10
- PrintStream to Writer"karl wettin" wrote:
>
> Java programmers,
>
> I've wrote this software that prints output to a PrintStream (usually
> System.err), but from time to time I would like to send the output to
> a Writer (ServletResponse.getWriter()) instead.
Change your logic. Write your software so that it always writes using a
Writer. In case you need to write to an OutputStream, use an
OutputStreamWriter.
Writers are newer than OutputStreams (added in Java 1.1). Because of
this, Writers know about OutputStreams, but OutputStreams don't know
anything about Writers. So the only bridge between them is a Writer
(OutputStreamWriter) that knows about an output stream.
> {
// > PrintStream out=System.err;
Writer out = OutputStreamWriter(System.err);
>
> void someMethod(ServletResponse reponse)
> {
// > this.out = new SomeStreamWriterWrapper(response.getWriter());
this.out = response.getWriter();
> }
> }
- 10
- How can i get the the data come from severlet?Hi,
That's the suituation.
There's a website using servlet to provide some information i need. I
can only get the html they provide for me. Their data will be update
every minite, but i can not stare at it and push "reload" button to get
the new data.
How can i get the data using a Java class from the website
automatically per minite without do the tedious work above.
Any idea?
- 10
- Orion - need to add customer parameterHi,
I have a large application which I need to split into 2 and put on
different servers because the applicaiton is becoming too big.
What I need is to add in a parameter which tells me if its Application
A or Application B.
Both applications will have the same code. The only difference is that
when you log onto the system it will some how read the parameter to let
it know which Application it should be and then it will display the
relevant menus. So if the parameter in one of the Orion says 'AppA'
then it will display Application A's menus and vica-versa for
Application B.
Can someone tell me which place is the best to place this parameter?
(e.g. application.xml)??
Also how would I read this parameter?
Please give example if possible.
Thanks
Simon
- 11
- need help with jar archivHi,
I need some help with my jar archive.
I need to read a file in my program. I do that with
FileReader.
To locate the file I use getClass().getResource("key/key.txt")
I used the above class.getResource so that teh programme locates the file
in the jar archive. But it doesn't work after getting packed in
jar, otherwise works perfectly alright.
I use the following command to make the jar:
jar cmf caesar/mainClass cipher.jar caesar/c*.class caesar/key/key.txt
Can somebody please help me with that.
I get a error-message as follows
file:\E:\myprogs\Security\cipher.jar!\caesar\key\key.txt ( The syntax for
the filename,
directory and data volume is wrong)
The relevant code lines:
URL fileUrl = getClass().getResource("key/key.txt");
// String filename = fileUrl.getFile();
System.out.println(fileUrl.getFile());
try {
System.out.println(fileUrl.getFile());
BufferedReader read =
new BufferedReader
(new FileReader(fileUrl.getFile()));
Regards,
Sunil
- 14
- JSP Code Review Tool or Syntax Analyzer?We use an automated Java source code review tool (Hammurpai) in our
company. It does the job. However, we write a substantial amout of JSP
code for web and voice applications. The Java code review tool says it
will also handle JSP, but you need to run it through Jasper first to
turn it in to *.java files. I've been searching all over, but can't
find what I need. I want to take a directory and sub-directories of
*.jsp files and run them through an automated tool that checks for
syntax, parameter naming conventions, closed attribute quotes, closing
tags, ample whitespace, quantity of comments, etc. I want it to show
the violations so the code can be fixed before being bundled and
deployed, only to find out later that it has a problem compiling
because of a missing closing quote. Does anything like this exist out
there?
- 15
- Need help in CLASSPATH/Packagehi everyone,
i am having a strange problem regarding package/classpath.
Very Sorry, Its a long post but please help.
I did like this:
I created MyMath.java file in C:\Java , the contents were:
package com.anbh.Maths;
public class MyMath {
public static int add(int x, int y) {
return x + y;
}
public static int sub(int x, int y) {
return x-y;
}
}
Created file UrMath.java again in C:\Java, contents were :
package com.anbh.Maths;
public class UrMath {
public String callMe() {
return "Inside CallMe()";
}
}
Created file TempClass again in C:\Java, Contents were
import com.anbh.Maths.*;
public class TempClass {
public static void main(String[] args) {
System.out.println(MyMath.add(-1, -1));
UrMath ob = new UrMath();
System.out.println(ob.callMe());
}
}
Then I compiled it like below: (My current directory was C:\Java)
javac -d . MyMath.java UrMath.java
This Complied successfully and created directories C:\Java\com\anbh\Maths.
Then I tried to compile TempClass.java like: (My current directory was C:\Java)
javac -classpath . TempClass.java
I got the error:
TempClass.java:6: cannot access MyMath
bad class file: .\MyMath.java
file does not contain class MyMath
Please remove or make sure it appears in the correct subdirectory of the classpath.
System.out.println(MyMath.add(-1, -1));
^
1 error
Now, when I changed the TempClass.java file's import statement as:-
import com.anbh.Maths.MyMath;
import com.anbh.Maths.UrMath;
i.e. I named every class individually, EVERYTHING WORKED FINE.
Why import com.anbh.Maths.* notation is not working???????
Please help, I had wasted 1 day on this.
Thanks in adv.
|
| Author |
Message |
HalcyonWild

|
Posted: 2005-8-5 22:57:00 |
Top |
java-programmer, When to synchronize a list
Hi,
I wanted to know when should I synchronize a list. No, this is not the
old question regarding ArrayList Vs Vector. My doubts are more related
to synchronization ( whether a plain ArrayList or synchronized
Arraylist or Vector)
The common answer I find is that Vector or synchronizedList( new
ArrayList ) should be used when two or more threads are accessing the
contents of the List.
For example, consider following code in a Java class.
Vector vec = new Vector();
for (int i = 0; i < somenumber; i++)
{
//do something
vec.add(new Integer(i));
//do more
}
My thought is that whether you use any list, you still would have to
make the loop synchronized. Even if a vector or synchronized ArrayList
is used, another piece of code might just come in and modify that
vector (not run that loop, but just want to modify vec ) before the for
loop comes back again to that place. This is because, synchronized list
means when one thread is updating, another cannot. But if the first
thread is not updating, other freely can. This might create
inconsistent data in the List.
As far as I understand, the synchronization in the Vector is on the
instance itself. So before calling any method on the Vector instance, a
lock is obtained by runtime. Once method execution is over, the lock is
available to any other thread.
This is more possible in Servlets or JSP. ( EJB , I do not think so,
because, a separate instance is assigned to each thread calling a
method in the EJB ).
Another example, would be using a List as a member inside a singleton
class. If two threads request the instance of the singleton, both will
get the reference to the same instance of the class. Say the second
thread gets an index and has to retrieve the object at that index
position in the list, while the first thread is updating the vector. It
might turn out that the value retreived by the second thread might not
be what it expected. So I would anyway have to synchronize the methods
in the singleton, to get a lock on that instance before attempting to
call any method on that instance.
When would I use a List and when would I use synchronized List. Does it
really make any difference whether I use Vector or ArrayList when I
have to synchronize all access to the List. Please give any example to
help me understand the situation.
I have searched google and also I have searched previous posts. I could
not find the answer to this specific question so I am posting this. I
did find lot of stuff related to ArrayList Vs Vector, and which is
better , but not related to synchronization and Lists.
Thanks.
|
| |
|
| |
 |
Thomas Weidenfeller

|
Posted: 2005-8-5 23:51:00 |
Top |
java-programmer >> When to synchronize a list
HalcyonWild wrote:
> The common answer I find is that Vector or synchronizedList( new
> ArrayList ) should be used when two or more threads are accessing the
> contents of the List.
This is the common, but to simplistic answer, as you have figured out by
yourself.
> My thought is that whether you use any list, you still would have to
> make the loop synchronized.
It depends ... No really, it depends on you usage of threads, your data
model, etc. In short, you are seeing the typical problems of thread save
programming. A sequence of code like
v.add(something);
v.add(somethingElse);
might be thread save or not, depending on the relation of 'something'
and 'somethingElse'. If your algorithm e.g. requires that your vector
always contains consecutive 'something', 'somethingElse' pairs, you can
get in trouble with this. If the particular order doesn't mater then the
above code is thread-save - maybe. Maybe, because you have to look at
the rest of the code, too. Whenever data is shared you have to carefully
look what happens with the data.
/Thomas
--
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
|
| |
|
| |
 |
Eric Sosman

|
Posted: 2005-8-6 0:30:00 |
Top |
java-programmer >> When to synchronize a list
HalcyonWild wrote:
> Hi,
>
> I wanted to know when should I synchronize a list. No, this is not the
> old question regarding ArrayList Vs Vector. My doubts are more related
> to synchronization ( whether a plain ArrayList or synchronized
> Arraylist or Vector)
> The common answer I find is that Vector or synchronizedList( new
> ArrayList ) should be used when two or more threads are accessing the
> contents of the List.
>
> For example, consider following code in a Java class.
>
> Vector vec = new Vector();
> for (int i = 0; i < somenumber; i++)
> {
> //do something
> vec.add(new Integer(i));
> //do more
> }
>
>
> My thought is that whether you use any list, you still would have to
> make the loop synchronized. Even if a vector or synchronized ArrayList
> is used, another piece of code might just come in and modify that
> vector (not run that loop, but just want to modify vec ) before the for
> loop comes back again to that place. This is because, synchronized list
> means when one thread is updating, another cannot. But if the first
> thread is not updating, other freely can. This might create
> inconsistent data in the List.
It depends on what your application thinks "inconsistent"
is. If you require that the values 0 through somenumber-1
appear in one contiguous stretch of the list, then yes: you
need to synchronize the entire loop so the entire loop becomes
"atomic." However, if you only require that all the numbers
get inserted into the list at some point (even though other
threads might delete some of them, insert others, or otherwise
fool around), then you don't need to synchronize the loop.
There's no one answer; it depends on your application.
Either way, the individual operations on the list must be
synchronized. This happens automatically with Vector and with
lists obtained from Collections.synchronizedList, but with a
plain ArrayList you need to synchronize explicitly.
> As far as I understand, the synchronization in the Vector is on the
> instance itself. So before calling any method on the Vector instance, a
> lock is obtained by runtime. Once method execution is over, the lock is
> available to any other thread.
Right. This makes individual operations "atomic," but
provides no guarantees for sequences of operations. For
example,
Vector v = ...;
...
if (! v.isEmpty())
Object obj = v.firstElement();
... might throw NoSuchElementException in a multithreaded
program where two or more threads have access to `v'.
> This is more possible in Servlets or JSP. ( EJB , I do not think so,
> because, a separate instance is assigned to each thread calling a
> method in the EJB ).
>
> Another example, would be using a List as a member inside a singleton
> class. If two threads request the instance of the singleton, both will
> get the reference to the same instance of the class. Say the second
> thread gets an index and has to retrieve the object at that index
> position in the list, while the first thread is updating the vector. It
> might turn out that the value retreived by the second thread might not
> be what it expected. So I would anyway have to synchronize the methods
> in the singleton, to get a lock on that instance before attempting to
> call any method on that instance.
Again, it depends on what your application needs. For
example, if you're using the Vector as a stack, where one thread
pushes things onto the stack and the other removes them, the
pusher can just do v.add(obj) and rely on the synchronization
within Vector to maintain consistency.
The popper, though, can't do things quite so simply. The
problem is that the popper wants to do something special when
the Vector is empty, so it needs to query the Vector's state
before attempting to remove anything. Both the query and the
removal are synchronized, but the combination isn't -- and the
state of affairs could change between the query and the pop.
To guard against this, the popper needs to do something like
Object poppedObj;
synchronized(v) {
if (v.isEmpty())
poppedObj = null;
else
poppedObj = v.remove(v.size() - 1);
}
Note that the pusher's v.add(obj) cannot be rewritten as
v.add(v.size(), obj) -- I imagine you can figure out why.
> When would I use a List and when would I use synchronized List. Does it
> really make any difference whether I use Vector or ArrayList when I
> have to synchronize all access to the List. Please give any example to
> help me understand the situation.
List is an interface implemented by several classes, some
of which synchronize their methods and some of which don't.
This is a case where the implementation details protrude through
the veneer of the interface contract. You can either rely on
knowing that Vector's methods are synchronized, or you can use
any List type (including Vector) with Collections.synchronizedList.
If two or more threads have access to the List, you must
somehow arrange for synchronization. The most convenient way to
do this is to make synchronization a property of the List itself,
either with Collections.synchronizedList or by using Vector. An
alternative is to use a "bare" List and synchronize every method
call manually, but this is both tedious and fragile.
However, as the examples above should show, synchronizing
the individual method calls is not always enough. If you're
going to traverse an entire List with an Iterator you need to
synchronize the entire traversal loop, not just the methods
you call inside it. If you're going to add something to the
List only if the List contains fewer than forty-two elements
already, you need to synchronize the entire query-and-add
"combo-operation." Your application determines what's needed.
> I have searched google and also I have searched previous posts. I could
> not find the answer to this specific question so I am posting this. I
> did find lot of stuff related to ArrayList Vs Vector, and which is
> better , but not related to synchronization and Lists.
--
email***@***.com
|
| |
|
| |
 |
Thomas G. Marshall

|
Posted: 2005-8-6 0:48:00 |
Top |
java-programmer >> When to synchronize a list
HalcyonWild coughed up:
> Hi,
>
> I wanted to know when should I synchronize a list. No, this is not the
> old question regarding ArrayList Vs Vector. My doubts are more related
> to synchronization ( whether a plain ArrayList or synchronized
> Arraylist or Vector)
> The common answer I find is that Vector or synchronizedList( new
> ArrayList ) should be used when two or more threads are accessing the
> contents of the List.
>
> For example, consider following code in a Java class.
>
> Vector vec = new Vector();
> for (int i = 0; i < somenumber; i++)
> {
> //do something
> vec.add(new Integer(i));
> //do more
> }
>
>
> My thought is that whether you use any list, you still would have to
> make the loop synchronized.
YES. If the loop requires (as is usually the case) that the body of it
remain atomic, then you must mutex out execution of the list.
Vector vec = new Vector();
[...]
synchronized(vec)
{
for (int i = 0; i < somenumber; i++)
{
//do something
vec.add(new Integer(i));
//do more
}
}
Try to synchronize only the minimum needed. You should not over
synchronize, unless it is truly hairy to do otherwise. That is, it is often
important to sacrifice runtime efficiency to keep later maintainability
intact, but lets leave that idea alone for now. And I'll skip giving you a
hairy example.
> Even if a vector or synchronized ArrayList
> is used, another piece of code might just come in and modify that
> vector (not run that loop, but just want to modify vec ) before the
> for loop comes back again to that place. This is because,
> synchronized list means when one thread is updating, another cannot.
> But if the first thread is not updating, other freely can. This might
> create inconsistent data in the List.
>
> As far as I understand, the synchronization in the Vector is on the
> instance itself. So before calling any method on the Vector instance,
> a lock is obtained by runtime.
Remember that that lock is only obtained when calling methods that are
synchronized, or when some block of clode is synchronized. The class
/itself/ is not synchronized per se, though when using that term, what is
meant is that the majority of its methods are synchronized.
> Once method execution is over, the
> lock is available to any other thread.
>
> This is more possible in Servlets or JSP. ( EJB , I do not think so,
> because, a separate instance is assigned to each thread calling a
> method in the EJB ).
>
> Another example, would be using a List as a member inside a singleton
> class. If two threads request the instance of the singleton, both will
> get the reference to the same instance of the class. Say the second
> thread gets an index and has to retrieve the object at that index
> position in the list, while the first thread is updating the vector.
> It might turn out that the value retreived by the second thread might
> not be what it expected. So I would anyway have to synchronize the
> methods in the singleton, to get a lock on that instance before
> attempting to call any method on that instance.
>
> When would I use a List and when would I use synchronized List. Does
> it really make any difference whether I use Vector or ArrayList when I
> have to synchronize all access to the List. Please give any example to
> help me understand the situation.
Take the example I gave above. That loop itself does infact lock out any
access to the vector while that loop is running. Technically speaking, if
all such access are externally synchronized like this, you would never have
to worry. /All/ such access.
But what if there is an unsynchronized call adding something to the vector
that is mid stream when this loop elsewhere starts to run. If you were
using an UNsynchronized arraylist instead of vector or synchronized
arraylist, then in the middle of an add(), the loop could start, grab the
lock (which does no good), and both the add and loop would be running at the
same time. OI.
> I have searched google and also I have searched previous posts. I
> could not find the answer to this specific question so I am posting
> this. I did find lot of stuff related to ArrayList Vs Vector, and
> which is better , but not related to synchronization and Lists.
Having been part of several of such threads, you ought to look again. ;)
--
Unix users who vehemently argue that the "ln" command has its arguments
reversed do not understand much about the design of the utilities. "ln
arg1 arg2" sets the arguments in the same order as "mv arg1 arg2".
Existing file argument to non-existing argument. And in fact, mv
itself is implemented as a link followed by an unlink.
|
| |
|
| |
 |
Yamin

|
Posted: 2005-8-6 5:14:00 |
Top |
java-programmer >> When to synchronize a list
This is really a design question that depends on your particular
situation.
I've found that trying to overencapsulate synchronization can often
lead to more problems that its worth.
If you are going to deal with the structure only within the confines of
add/remove or push/pop or whatever...then by all means use one of the
storage classes that contain synchronization within the methods. For
example, if you're using a fifo queue for messages. Then you probably
aren't going to need to operate on the queue itself...you'll just need
to add,remove,clear the queue...
But if, as in your example with the for loop, you actually plan to
'operate on' the structure itself, I would suggest not encapsulating
the synchronization and instead rely on an unsynchronized storage
class, with explicit synchronized blocks around code that needs to be
protected.
Just my two cents...
PS...I know I may not be clear on what 'operate on' means...but
hopefully you get that point. Basically if any operation you plan to
take on teh structure extends beyond a single method call to the
structure, I would use explicit synchronized blocks.
Yamin Bismilla
|
| |
|
| |
 |
AWieminer

|
Posted: 2005-8-9 0:56:00 |
Top |
java-programmer >> When to synchronize a list
> As far as I understand, the synchronization in the Vector is on the
> instance itself. So before calling any method on the Vector instance, a
> lock is obtained by runtime. Once method execution is over, the lock is
> available to any other thread.
> Another example, would be using a List as a member inside a singleton
> class. If two threads request the instance of the singleton, both will
> get the reference to the same instance of the class. Say the second
> thread gets an index and has to retrieve the object at that index
> position in the list, while the first thread is updating the vector. It
> might turn out that the value retreived by the second thread might not
> be what it expected. So I would anyway have to synchronize the methods
> in the singleton, to get a lock on that instance before attempting to
> call any method on that instance.
> When would I use a List and when would I use synchronized List. Does it
> really make any difference whether I use Vector or ArrayList when I
> have to synchronize all access to the List. Please give any example to
> help me understand the situation.
I never use Vector class, but always ArrayList class. Then if I have
multithreading apps I analyze the code. It's really easy to do if does
not care about the optimization issues to avoid unnecessary locks.
* if list is single thread use, no point synchronisation (method level
instance or private single thread member or single thread app).
* if list is readonly use then no syncronization needed. This is common
case for configuration values which are initialized at the app startup
phase.
* if list is modified and read from multiple threads, then I use
"Collections.synchronizedList" wrapper. Store a returned reference and
use it everywhere I need that list.
JRE1.5 has more list implementations to choose from. You could use
copyOnWrite implementation to avoid syncronization in multithread use.
Here all read operations are safe and write operation creates a new
internal list buffer.
|
| |
|
| |
 |
Thomas G. Marshall

|
Posted: 2005-8-9 1:06:00 |
Top |
java-programmer >> When to synchronize a list
AWieminer coughed up:
>> As far as I understand, the synchronization in the Vector is on the
>> instance itself. So before calling any method on the Vector
>> instance, a lock is obtained by runtime. Once method execution is
>> over, the lock is available to any other thread.
>
>> Another example, would be using a List as a member inside a singleton
>> class. If two threads request the instance of the singleton, both
>> will get the reference to the same instance of the class. Say the
>> second thread gets an index and has to retrieve the object at that
>> index position in the list, while the first thread is updating the
>> vector. It might turn out that the value retreived by the second
>> thread might not be what it expected. So I would anyway have to
>> synchronize the methods in the singleton, to get a lock on that
>> instance before attempting to call any method on that instance.
>
>> When would I use a List and when would I use synchronized List. Does
>> it really make any difference whether I use Vector or ArrayList when
>> I have to synchronize all access to the List. Please give any
>> example to help me understand the situation.
>
> I never use Vector class, but always ArrayList class. Then if I have
> multithreading apps I analyze the code. It's really easy to do if does
> not care about the optimization issues to avoid unnecessary locks.
>
> * if list is single thread use, no point synchronisation (method level
> instance or private single thread member or single thread app).
> * if list is readonly use then no syncronization needed.
*WARNING* ! This may be true for the built-in collection classes (I haven't
looked) but it is perilous to assume it is ok in general. Many accessor
methods actually change the internal state of their object, even if
slightly, and temporarily. It's not ideal, nor even good design--in fact
it's almost certainly terrible design. But you have to "worry" about it
unless you fully trust that:
1. the code doesn't do it.
2. the code is *very* unlikely to do it in the future.
Making such assumptions is the halmark of fragility.
> This is
> common case for configuration values which are initialized at the app
> startup phase.
> * if list is modified and read from multiple threads, then I use
> "Collections.synchronizedList" wrapper. Store a returned reference and
> use it everywhere I need that list.
>
> JRE1.5 has more list implementations to choose from. You could use
> copyOnWrite implementation to avoid syncronization in multithread use.
> Here all read operations are safe and write operation creates a new
> internal list buffer.
--
Unix users who vehemently argue that the "ln" command has its arguments
reversed do not understand much about the design of the utilities. "ln
arg1 arg2" sets the arguments in the same order as "mv arg1 arg2".
Existing file argument to non-existing argument. And in fact, mv
itself is implemented as a link followed by an unlink.
|
| |
|
| |
 |
Eric Sosman

|
Posted: 2005-8-9 1:20:00 |
Top |
java-programmer >> When to synchronize a list
Thomas G. Marshall wrote:
> AWieminer coughed up:
>>* if list is single thread use, no point synchronisation (method level
>>instance or private single thread member or single thread app).
>>* if list is readonly use then no syncronization needed.
>
> *WARNING* ! This may be true for the built-in collection classes (I haven't
> looked) but it is perilous to assume it is ok in general. Many accessor
> methods actually change the internal state of their object, even if
> slightly, and temporarily. It's not ideal, nor even good design--in fact
> it's almost certainly terrible design. [...]
The warning is a good one, but is "terrible design"
defensible? Self-organizing data structures (e.g. splay
trees) certainly seem to require the ability to modify
their internal state even on read accesses. There's also
the matter of instrumentation: a hash table implementation
might keep track of things like collision rates and probe
counts; such statistics would be ancillary in a sense, but
would certainly be part of the internal state.
--
email***@***.com
|
| |
|
| |
 |
Thomas Hawtin

|
Posted: 2005-8-9 1:34:00 |
Top |
java-programmer >> When to synchronize a list
AWieminer wrote:
>
> * if list is readonly use then no syncronization needed. This is common
> case for configuration values which are initialized at the app startup
> phase.
At some point the list will have been written to, so there needs to be
something done to ensure uninitialised values are seen.
In most cases the list will be created in class initialisation. So long
as the list doesn't leak to another thread during the initialisation
process, the class initialisation happens-before any use of the class
and hence list.
Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
|
| |
|
| |
 |
Thomas G. Marshall

|
Posted: 2005-8-9 10:49:00 |
Top |
java-programmer >> When to synchronize a list
Eric Sosman coughed up:
> Thomas G. Marshall wrote:
>> AWieminer coughed up:
>>> * if list is single thread use, no point synchronisation (method
>>> level instance or private single thread member or single thread
>>> app). * if list is readonly use then no syncronization needed.
>>
>> *WARNING* ! This may be true for the built-in collection classes (I
>> haven't looked) but it is perilous to assume it is ok in general.
>> Many accessor methods actually change the internal state of their
>> object, even if slightly, and temporarily. It's not ideal, nor even
>> good design--in fact it's almost certainly terrible design. [...]
>
> The warning is a good one, but is "terrible design"
> defensible? Self-organizing data structures (e.g. splay
> trees) certainly seem to require the ability to modify
> their internal state even on read accesses. There's also
> the matter of instrumentation: a hash table implementation
> might keep track of things like collision rates and probe
> counts; such statistics would be ancillary in a sense, but
> would certainly be part of the internal state.
Yes, you're right. I was careful to say " /almost/ certainly".
But in any case, the warning is clear. Accessors can mutate behind the
scenes.
--
Onedoctortoanother:"Ifthisismyrectalthermometer,wherethehell'smypen???"
|
| |
|
| |
 |
Ingo R. Homann

|
Posted: 2005-8-9 13:55:00 |
Top |
java-programmer >> When to synchronize a list
Hi,
AWieminer wrote:
>...
> * if list is modified and read from multiple threads, then I use
> "Collections.synchronizedList" wrapper. Store a returned reference and
> use it everywhere I need that list.
Note that this is not sufficient very often:
for(int i=0;i<arrayList.size();i++) {
// (*)
System.out.println(arrayList.get(i));
}
Consider another Thread will remove some elements when the current
Thread is at the marked position (*). This will cause an
IndexOutOfBoundsException, no matter if the the arrayList is a
synchronized List or not.
It is necessary to synchronize the *complete* for-loop.
Ciao,
Ingo
|
| |
|
| |
 |
HalcyonWild

|
Posted: 2005-8-9 21:32:00 |
Top |
java-programmer >> When to synchronize a list
HalcyonWild wrote:
> Hi,
>
> I wanted to know when should I synchronize a list. No, this is not the
> old question regarding ArrayList Vs Vector. My doubts are more related
> to synchronization ( whether a plain ArrayList or synchronized
> Arraylist or Vector)
> The common answer I find is that Vector or synchronizedList( new
> ArrayList ) should be used when two or more threads are accessing the
> contents of the List.
>
Helped me a lot to clear my understanding.
Thanks a lot for all replies.
Please do post if anyone has more ideas.
|
| |
|
| |
 |
Thomas G. Marshall

|
Posted: 2005-8-10 3:54:00 |
Top |
java-programmer >> When to synchronize a list
Ingo R. Homann coughed up:
> Hi,
>
> AWieminer wrote:
>> ...
>> * if list is modified and read from multiple threads, then I use
>> "Collections.synchronizedList" wrapper. Store a returned reference
>> and use it everywhere I need that list.
>
> Note that this is not sufficient very often:
>
> for(int i=0;i<arrayList.size();i++) {
> // (*)
> System.out.println(arrayList.get(i));
> }
>
> Consider another Thread will remove some elements when the current
> Thread is at the marked position (*). This will cause an
> IndexOutOfBoundsException, no matter if the the arrayList is a
> synchronized List or not.
>
> It is necessary to synchronize the *complete* for-loop.
YES! I absolutely cannot believe how very many engineers just don't
understand this. I've used the following example everywhere I can, even a
few times in usenet:
thing.set(thing.get() + 1);
is *NOT* safe even if .set() and .get() are synchronized! In this
particular case, it also messes with how you read. To many it looks as if
the set() is establishing the lock, and everything else happens within it,
which is a mistake.
FURTHERMORE, I honestly believe that most engineers out there (yes, I said
most) do not understand synchronization at all, and view it as some sort of
"magical idiom" to add to things when they flake out.
|
| |
|
| |
 |
John Currier

|
Posted: 2005-8-10 4:03:00 |
Top |
java-programmer >> When to synchronize a list
Thomas G. Marshall wrote:
> Ingo R. Homann coughed up:
> > Hi,
> >
> > AWieminer wrote:
> >> ...
> >> * if list is modified and read from multiple threads, then I use
> >> "Collections.synchronizedList" wrapper. Store a returned reference
> >> and use it everywhere I need that list.
> >
> > Note that this is not sufficient very often:
> >
> > for(int i=0;i<arrayList.size();i++) {
> > // (*)
> > System.out.println(arrayList.get(i));
> > }
> >
> > Consider another Thread will remove some elements when the current
> > Thread is at the marked position (*). This will cause an
> > IndexOutOfBoundsException, no matter if the the arrayList is a
> > synchronized List or not.
> >
> > It is necessary to synchronize the *complete* for-loop.
>
> YES! I absolutely cannot believe how very many engineers just don't
> understand this. I've used the following example everywhere I can, even a
> few times in usenet:
>
> thing.set(thing.get() + 1);
>
> is *NOT* safe even if .set() and .get() are synchronized! In this
> particular case, it also messes with how you read. To many it looks as if
> the set() is establishing the lock, and everything else happens within it,
> which is a mistake.
>
> FURTHERMORE, I honestly believe that most engineers out there (yes, I said
> most) do not understand synchronization at all, and view it as some sort of
> "magical idiom" to add to things when they flake out.
I run into that frequently when dealing with Iterators/Enumerators over
collections that are supposedly synchronized. Many developers don't
realize the exposure.
John
http://schemaspy.sourceforge.net
|
| |
|
| |
 |
Thomas Hawtin

|
Posted: 2005-8-10 4:41:00 |
Top |
java-programmer >> When to synchronize a list
Thomas G. Marshall wrote:
>
> FURTHERMORE, I honestly believe that most engineers out there (yes, I said
> most) do not understand synchronization at all, and view it as some sort of
> "magical idiom" to add to things when they flake out.
Yup. I've met some developers who were very proud that they had used the
synchronized keyword. Never mind the deadlocks and race conditions all
over the shop. It was so bad that even people who worked in the same
room refused to use the application.
I must admit though, in my first year of Java I was a bit out of my
depth with it. Doug Lea's book should be compulsory reading for anyone
using threads and Java.
Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
|
| |
|
| |
 |
Patricia Shanahan

|
Posted: 2005-8-10 4:43:00 |
Top |
java-programmer >> When to synchronize a list
John Currier wrote:
> Thomas G. Marshall wrote:
>
>>Ingo R. Homann coughed up:
>>
>>>Hi,
>>>
>>>AWieminer wrote:
>>>
>>>>...
>>>>* if list is modified and read from multiple threads, then I use
>>>>"Collections.synchronizedList" wrapper. Store a returned reference
>>>>and use it everywhere I need that list.
>>>
>>>Note that this is not sufficient very often:
>>>
>>>for(int i=0;i<arrayList.size();i++) {
>>> // (*)
>>> System.out.println(arrayList.get(i));
>>>}
>>>
>>>Consider another Thread will remove some elements when the current
>>>Thread is at the marked position (*). This will cause an
>>>IndexOutOfBoundsException, no matter if the the arrayList is a
>>>synchronized List or not.
>>>
>>>It is necessary to synchronize the *complete* for-loop.
>>
>>YES! I absolutely cannot believe how very many engineers just don't
>>understand this. I've used the following example everywhere I can, even a
>>few times in usenet:
>>
>> thing.set(thing.get() + 1);
>>
>>is *NOT* safe even if .set() and .get() are synchronized! In this
>>particular case, it also messes with how you read. To many it looks as if
>>the set() is establishing the lock, and everything else happens within it,
>>which is a mistake.
>>
>>FURTHERMORE, I honestly believe that most engineers out there (yes, I said
>>most) do not understand synchronization at all, and view it as some sort of
>>"magical idiom" to add to things when they flake out.
>
>
> I run into that frequently when dealing with Iterators/Enumerators over
> collections that are supposedly synchronized. Many developers don't
> realize the exposure.
>
> John
> http://schemaspy.sourceforge.net
>
The newsgroup thread subject itself contains one of the key problems.
The question should be something like "How to design shared data
structure operations to ensure multi-thread safety?"
Patricia
|
| |
|
| |
 |
Kenneth P. Turvey

|
Posted: 2005-8-10 5:18:00 |
Top |
java-programmer >> When to synchronize a list
Thomas Hawtin wrote:
> I must admit though, in my first year of Java I was a bit out of my
> depth with it. Doug Lea's book should be compulsory reading for anyone
> using threads and Java.
If you learned C first with POSIX or SVR4 IPC you would think Java is a
wonderful simplification. :-)
--
Kenneth P. Turvey <email***@***.com>
|
| |
|
| |
 |
Thomas Hawtin

|
Posted: 2005-8-10 6:20:00 |
Top |
java-programmer >> When to synchronize a list
Kenneth P. Turvey wrote:
> Thomas Hawtin wrote:
>
>>I must admit though, in my first year of Java I was a bit out of my
>>depth with it. Doug Lea's book should be compulsory reading for anyone
>>using threads and Java.
>
> If you learned C first with POSIX or SVR4 IPC you would think Java is a
> wonderful simplification. :-)
I got the mechanics of it, but I just didn't grok how it was really all
supposed to fit together. I understood I should synchronise even if I
was doing a single operation. I was happy using repaint events because
EventQueue.invokeLater wasn't there yet. But there was something missing
at a higher level, which I guess is much the same however the mechanics
of it are exposed.
Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
|
| |
|
| |
 |
Thomas G. Marshall

|
Posted: 2005-8-10 8:01:00 |
Top |
java-programmer >> When to synchronize a list
Thomas Hawtin coughed up:
> Thomas G. Marshall wrote:
>>
>> FURTHERMORE, I honestly believe that most engineers out there (yes,
>> I said most) do not understand synchronization at all, and view it
>> as some sort of "magical idiom" to add to things when they flake out.
>
> Yup. I've met some developers who were very proud that they had used
> the synchronized keyword. Never mind the deadlocks and race
> conditions all over the shop. It was so bad that even people who
> worked in the same room refused to use the application.
A note to this. Many shriek in horror over this, but I strongly suggest
most (but particularly newbies) to adopt this:
public void method()
{
synchronized(this)
{
}
}
Instead of the ubiquitous
public synchronized void method()
{
}
For the following reasons:
1. It firms up in their noggins just what object is holding the lock
2. It is only the barest smidgeon slower (I've never met anyone who can
measure it)
3. It allows you (and further maintainers down the road) to easily move
things not requiring protection before and after the lock.
Many times, you'll discover that the vast majority of a synchronized method
does not require the lock at all, which makes #3 above important.
>
> I must admit though, in my first year of Java I was a bit out of my
> depth with it. Doug Lea's book should be compulsory reading for anyone
> using threads and Java.
--
If I can ever figure out how, I hope that someday I'll
succeed in my lifetime goal of creating a signature
that ends with the word "blarphoogy".
|
| |
|
| |
 |
Kenneth P. Turvey

|
Posted: 2005-8-10 8:17:00 |
Top |
java-programmer >> When to synchronize a list
Thomas G. Marshall wrote:
> Many times, you'll discover that the vast majority of a synchronized
> method does not require the lock at all, which makes #3 above important.
If you are writing small self contained methods that only do one thing, this
shouldn't matter.
--
Kenneth P. Turvey <email***@***.com>
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- Java and colour management...I have colour profile applied to my monitor.
When I browse a website that needs the Java plugin to run, it removes the
colour corrections making my display too bright! WHY the hell does java do
anything to my display???
Thanks.
- 2
- 3
- Another error creating JVM through JNII notice that there is another poster with a similar problem to mine,
but he's on Unix and I am on Windows, and I think there may be a
setup/config problem, so I am starting a new thread
I am also getting an error creating the JVM, I am using j2sdk1.4.2_04
with MSDEV 6.0 and have cut'n'pasted about three different pieces of
sample code ( I won't post loads of code here) from working examples
found on the web, they all fail on the call to JNI_CreateJavaVM with an
error code of -1
I am wondering is there are any common setup problems, perhaps having
dlls in the wrong place of environment variables set wrongly, that
might be a cause of this problem?
Here is an example of one code sample I tried that did not work.
Incidentally if I set the version wrong, I get a different error code
(-3, which is to indicate wrong version)
jint ret;
JavaVM* jvm;
JNIEnv* env;
JavaVMInitArgs args;
JavaVMOption options[1];
args.version = JNI_VERSION_1_2;
args.nOptions = 1;
options[0].optionString = "-Djava.class.path=c:\\";
args.options = options;
args.ignoreUnrecognized = JNI_FALSE;
ret = JNI_CreateJavaVM(&jvm, (void **)&env, &args);
- 4
- creating classes dynamicallyHI is it possible to create classes dynamically and if so how? What im
trying to do is have a user enter names into a textbox and use these
names to create instances of classes dynamically. the code below doesnt
work once never mind for numerous classes?????
String help= TextField.getText();
help = new SOP();
cheers
- 5
- JVM crashes when calling C++ DLLhi all,
I am calling functions in existing C\C++ program (DLL) through a
wrapper C++ program (another DLL) from java.
ie java <---->Wrapper C++ <-----> Ordinary C++ function
My problem is JVM crashes(some times) and gives the following error,
An unexpected exception has been detected in native code outside the
VM.
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred
at PC=0x80C2F75
Function=[Unknown.]
Library=(N/A)
NOTE: We are unable to locate the function name symbol for the error
just occurred. Please refer to release documentation for
possible
reason and solutions.
Current Java thread:
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:1647)
at java.lang.Class.getMethod0(Class.java:1893)
at java.lang.Class.getMethod(Class.java:976)
at javax.swing.UIDefaults.getUI(UIDefaults.java:726)
at javax.swing.UIManager.getUI(UIManager.java:784)
at javax.swing.JToolTip.updateUI(JToolTip.java:82)
at javax.swing.JToolTip.<init>(JToolTip.java:64)
at javax.swing.JComponent.createToolTip(JComponent.java:2603)
at javax.swing.ToolTipManager.showTipWindow(ToolTipManager.java:257)
at javax.swing.ToolTipManager$insideTimerAction.actionPerformed(ToolTipManager.java:689)
at javax.swing.Timer.fireActionPerformed(Timer.java:271)
at javax.swing.Timer$DoPostEvent.run(Timer.java:201)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
Dynamic libraries:
0x7CC00000 - 0x7CC1D000 C:\WINDOWS\SYSTEM\IMAGEHLP.DLL
Heap at VM Abort:
Heap
def new generation total 4608K, used 234K [0x10010000, 0x10510000,
0x10ed0000)
eden space 4096K, 1% used [0x10010000, 0x10021eb0, 0x10410000)
from space 512K, 31% used [0x10490000, 0x104b8a80, 0x10510000)
to space 512K, 0% used [0x10410000, 0x10410000, 0x10490000)
tenured generation total 60544K, used 11740K [0x10ed0000,
0x149f0000, 0x1c010000)
the space 60544K, 19% used [0x10ed0000, 0x11a47348, 0x11a47400,
0x149f0000)
compacting perm gen total 12032K, used 11914K [0x1c010000,
0x1cbd0000, 0x20010000)
the space 12032K, 99% used [0x1c010000, 0x1cbb2ad0, 0x1cbb2c00,
0x1cbd0000)
Local Time = Thu Aug 26 18:58:43 2004
Elapsed Time = 41
#
# The exception above was detected in native code outside the VM
#
# Java VM: Java HotSpot(TM) Client VM (1.4.2_02-b03 mixed mode)
#
Can Any one give me a solution to this problem or way to find out the
cause of the problem,
Thanks and Regards,
Chella.mani
- 6
- Java process title editingI need a component that takes a String and puts it into Unix process
table by calling natively setproctitle. On Windows it can do nothing, I
don't care.
Also a possibility to use variables such as number_of_threads would be cool.
Why? When running a lot of Java server stuff on a Linux box it's really
hard to tell which process is which. Especially in production
environment "kill -9":ing makes me always feel quite uncomfortable...
If there is no such thing, then I'll have to roll my own. But better to
check first, don't wan't to reinvent stuff. :) Google didn't turn out
anything. ..
- 7
- Why have the header 'public static void main(String[] args)' at all?Stewart Gordon wrote:
> jAnO! wrote:
> > How's that?
> > I thought that your main thread maintains a !dead state troughout the
> > runtime of your application.
>
> We're talking about the method called main, not the main thread.
Even so, both the main method and the main thread exit directly toward
the beginning of a typical GUI application. What may *not* end, on some
operating systems, is the native OS-level thread that is used to
implement Java's concept of the main thread.
It's undefined whether that OS-level thread lives or not following the
termination of Java's main thread. It must on many platforms in order
to get around POSIX and other similar thread conventions (including
Win32, IIRC) that designate it as a special thread. On a system that
implemented a very different threading convention, though, which didn't
carry POSIX and Win32's pre-multithreading baggage, it would probably
not be necessary.
--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
- 8
- tomcat authentication questionI'm fairly new to configuring server.xml and web.xml files in tomcat 4.
I am trying to require password authentication for access to a
subdirectory called "update" located within ROOT. I want all files
located directly in ROOT to be available without a password. I am having
trouble determing the correct path to use for the <url-pattern> in the
web.xml file in WEB-INF so that only the files in the subdirectory
"update" within ROOT are password protected.
If I use <url-pattern>/*</url-pattern> then no pages on the site may be
accessed without a password no matter their location. I am presuming
that this means I have set up the basic authentication correctly in
tomcat-users.xml, server.xml (in conf) and web.xml (in WEB-INF) but that
I now simply need to put the correct path into the <url-pattern> in
web.xml.
However, when I use <url-pattern>/update/*</url-pattern>, I can access
all of the pages within the update directory without being asked for a
password. I've experimented with many different paths and have not had
luck with any. I have been careful to close my browser and open a new
one each time between tests. I've also tried restarting tomcat for every
new test. Nothing works.
In my server.xml file, <Realm
className="org.apache.catalina.realm.MemoryRealm" /> is located within
the <Engine> tag (not within <Host> or <context>).
Have hunted around for a solution without much luck. I assume that I am
missing something very simple.
Here is my complete web.xml file...
<web-app>
<display-name>SMUpdate App webxml</display-name>
<!-- form login security tags -->
<security-constraint>
<web-resource-collection>
<web-resource-name>SMUpdate</web-resource-name>
<url-pattern>/*</url-pattern> <!-- this works but causes password
to be required for access to all pages on entire site -->
</web-resource-collection>
<auth-constraint>
<role-name>smupdate</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>SMUpdate</realm-name>
</login-config>
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
</web-app>
Any suggestions would be very much appreciated.
Thanks.
- 9
- servlet mapping problemsHey guys/gals. My first attempted at servlet mapping flubbed.
Background:
A friend at work suggested I store my source in webapps\wbrl\jsp
So I have Tomcat\webapps\wbrl\jsp\WebRoll.jsp
Currently I type http://localhost:8080/wbrl/jsp/WebRoll3.jsp
This brings up my application successfully.
I would like to be able to type http://localhost:8080/wbrl and have
it bring up my web page.
So I tried to change the web.xml, but it doesnt work.
<servlet>
<servlet-name>WebRoll3</servlet-name>
<servlet-class>WebRoll3</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>WebRoll3</servlet-name>
<url-pattern>/wbrl/*</url-pattern>
</servlet-mapping>
<url-pattern>/wbrl/*</url-pattern> causes "Wrapper cannot find servlet
class WebRoll3 or a class it"
How do i fix this? Do I use filter mapping? I got totally lost in the
filter mapping explanation.
- 10
- Java coding with Agile PLM SDK - QuestionHello,
I was wondering if any one out here is dealing with a PALM System called
Agile and has some experience with the Agile SDK. If so can you email me, I
have a question on the SDK.
Also if any one know where I might find like a forum or message board that
deals with The Agile PALM system that would be help full too.
Thanks
-Dale
- 11
- Graphics2D question.Hello,
I want to build my application from three main classes.
1. A frame class to handle file operations.
2. A Drawing panel to render images to.
3. An engine to perform the actual rendering.
All the examples I have read so far for Image stuff in Java have
everything stuffed into one monolithic class, and the crux of the
rendering seems to be done in paint(Graphics g) or
paintComponent(Graphics g) using a g2d object cast againg the parameter g.
If I wanted to do calculations for rotations translations etc I can do
this with the AffineTransform class setX methods, but the drawImage
method of g2d seems to be handled in the paint/paintComponent methods.
This is fine until I want to specify x, y arguments in the drawImage
Method as neither Paint or PaintComponent take these parameters in their
method signature how can I do this, is there another way to draw apart
from the paint/paint component methods?
Any help appreciated.
- 12
- hashCode and equals (again)Hello,
I have spent a great deal of time reading through the postings in this
group as well as tutorials/explanations on sites elsewhere (i.e.,
Roedy's, etc.), but have not been able to get a good grasp of hashCode
and equals. I understand most of the rules for hashCode are defined
for use of objects in maps and other comparable collections, so it is
from that POV that I am trying to get a good grasp of the concepts.
Please help if you can - especially the SCCE later.
1. Originally, I thought that it made sense to make an equals method
that uses hashCode as its criteria for equality. However, as I now
understand hashCode, the code _must_ be the same for equal objects,
BUT it is _possible_ to be the same for non-equal objects. Am I
stating this correctly?
2. When would one use a set of criteria to determine equality that is
different from the criteria used to generate a hashCode?
3. Why aren't the hashCode_s in the following code the same?
package hashcode;
public class Main
{
public static void main(String[] args)
{
int[] a = { 1, 7, 0, 0 };
int[] b = { 1, 7, 0, 0 };
System.out.println( "equals: " + a.equals( b ) );
System.out.println( "hash a: " + a.hashCode() );
System.out.println( "hash b: " + b.hashCode() );
Integer[] c = { 1, 7, 0, 0 };
Integer[] d = { 1, 7, 0, 0 };
System.out.println( "equals: " + c.equals( d ) );
System.out.println( "hash c: " + c.hashCode() );
System.out.println( "hash d: " + d.hashCode() );
int[] e = a.clone();
Integer[] f = c.clone();
System.out.println( "equals: " + a.equals( e ) );
System.out.println( "hash a: " + a.hashCode() );
System.out.println( "hash e: " + e.hashCode() );
System.out.println( "equals: " + c.equals( f ) );
System.out.println( "hash c: " + c.hashCode() );
System.out.println( "hash f: " + f.hashCode() );
}
}
Thanks,
Todd
- 13
- Middle Tier for Java and PHPHi,
Let's say you have a Java SE Application and a PHP Web App that are both
accessing a database directly. You want to control things more formally
by using a common middle tier (enforcing things in addition to database
constraints / sprocs).
Any experience on what works and/or recommendations?
Thanks,
John
- 14
- i am new to javaIn article <eje544$gkc$email***@***.com>, Prejith took
the hamburger meat, threw it on the grill, and I said "Oh Wow"...
> hello
>
> i am new to java programming..since it is a requirement for my task i am
> suppose to write java jobs..i had a small training in core java concepts for
> 3 days..
>
> my question here is i am suppose to use some file handling and exception
> handling in my programme..can you help me with the above mentioned
> concepts...
>
> Regards
> Prejith
Okay, it breaks down like this. File handling is just that, things you
want to do to a file. You can read files and write to them. Whenever
you read to or write from a file, you have to handle exceptions, the
main one being FileNotFoundException (in case there's no file to be
found). That's why they want to empahasize both of those points.
Whenever you're doing I/O, you have to use try/catch blocks. I think
I/O exception's the other one you have to handle but my memory is
fuzzy on it right now.
HTH
--
trippy
mhm31x9 Smeeter#29 WSD#30
sTaRShInE_mOOnBeAm aT HoTmAil dOt CoM
NP: "All I Really Want" -- Alanis Morissette
"Now, technology's getting better all the time and that's fine,
but most of the time all you need is a stick of gum, a pocketknife,
and a smile."
-- Robert Redford "Spy Game"
- 15
- Tomcat is giving the wrong MIME type?I use Tomcat serves a web application. I put all the files including
jsp, css and javascript file inside the Tomcat server.
When I request a jsp page through both Firefox1.5 and IE6, I found the
css and the javascript files are not loaded correctly.
I used LiveHttpHeaders to inspect the request and response headers. I
found that the server is giving text/html to the Content-Type of all
the files.
Is the problem in Tomcat configuration or in the browser?
Any idea?
TIA...
|
|
|