Jeremy Thornton

Ranch Hand
+ Follow
since Feb 21, 2002
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jeremy Thornton

Hi stan,

Deadlock occurs when two (or more) threads hold a lock that the others need to complete.
Thread A holds a lock on object 1 and needs a lock on object 2 to complete.
Thread B holds a lock on object 2 and needs a lock on object 1 to complete.

Your code starts two Threads (incidentaly the name TransThread1 is a bit misleading as its not a Thread) which use the same Runnable object.
For the first Thread the str member of the Runnable object *may* be set to "Method" when it gets to the place in the run() method that uses it.
For the second Thread the str memeber of the Runnable object *will* be set to "Method".

As your using separate Threads, each could run before, after or concurrently with the other.

You're getting a lock on an object which changes at run time - probably not what you intended i.e. the objects created for "" and for "Method" have different locks and if str member has been changed the second thread will always successfully get the lock regardless of whether the original thread holds the lock for a different object.

In addition, you always get the locks in the same order. Even if the same object is synchronized on, the second thread will just wait until the first releases the lock and then go about its business.

In short, if you want to see deadlocking in all its glory you'll need to change your runnable class to do something like

Hope this makes sense,
[ May 25, 2004: Message edited by: Jeremy Thornton ]

If you really want to use A and B without creating objects you can use static methods or attributes. These belong to the class rather than any particular instance.


Hope this helps,

[ edited to fix broken code tags -ds ]
[ May 17, 2004: Message edited by: Dirk Schreckmann ]
18 years ago
No worries.
If only life let us spend all day meandering about the ranch...
18 years ago
No worries - promise not to overload you over the festive break :-)
18 years ago
Do you mean multiple inheritance?
If so, preventing multiple inheritance avoids many of the associated problems such as where D extends B and C both of which extend A. If you call a method on D which is implemented in B and C, which implementation do you choose?
Multi level inheritance (e.g. C extends B extends A) is allowed.
18 years ago
Maps contain a key, value pair.
If you want to key multiple objects just make the value a Collection.
18 years ago
I think that it just means that there has been a problem writing to the underlying socket and this has arisen because the other side of the connection has killed the socket.
I'm trying to post data to a secure webserver. If I run the webserver and my client application on the same box then all is ok (using a key created for localhost).
If I generate a key for the webserver for my IP address and then try to hit it from another machine, the handshake seems to go ok until I get a
"HTTPS hostname wrong: should be <my ip address>" (where my ip address is my actual IP address.
In the past when I've seen this error it has been followed by
", but cert says <host>" or something similar.
The IP address used in the public key seems to match the IP I'm specifying as the address "https://my ip address:442/testwebserver".
I'm confused... any suggestions?
Just for explicitness.
Means there's no ambiguity about what was intended.
18 years ago
I haven't used it but I would imagine that launching using javaw rather than java should do the trick.
18 years ago
Nope, only in terms of readability.
Your first example is usually the prefered layout, but it makes no difference to the semantics of the statement.
18 years ago

Actually, you need to *remove* the return type, as a constructor doesn't have one.

Trying to walk and chew gum at the same time again
18 years ago
I suspect it's because you are not calling a constructor.

returns a DirContext, not an ldapConnection which makes it a method rather than a constructor.
Try changing the return type and see what happens.
18 years ago
What's the problem with using a temporary variable?
If you are convinced that you don't want to use one, the only way that I can think of is to define a separator character e.g. '#', "append" it to the end of one of the Strings followed by the other String and then parse the required bit of the compound String into each variable.
String one = "one" ;
String two = "two" ;
one = one + "#" + two ;
int separatorIndex = one.indexof( '#' );
two = one.substring( 0, separatorIndex );
one = one.substring( separatorIndex );
Or something like that.
This will of course end up creating a number of new objects while during the manipulation as Strings are immutable thereby negating any performance gain that you would have achieved by not specifying an extra variable.
18 years ago
One way is to use an InputStream capable of reading a line at a time and then feed each line into a StringTokenizer. then read the tokens from the Tokeniser into a collection, maybe sort by length and write out all but the longest string.
18 years ago