473,387 Members | 3,787 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Deadlock... i think

I apologize in advance for the length of the note, and the source code
included.

I posted earlier under the title "Double streams", where i wanted to
use an RMI object as a sort of proxy for two clients to exchange data
via streams. I kinda failed, but now i'm trying something new. This
doesn't work either, but this time i think someone might be able to
solve it, since i'm not adept at using threads and i think that's
where the problem is. :)

The source for ByteHolder and RemoteByteHolder is included below. A
server is run, making a ByteHolder, BH, available via RMI.

Client A obtains the reference to BH, and passes this on to its
FooOutputStream, which extends OutputStream and implements the
write(int b) method by calling putByte(b) on BH.

Client B also gets BH, passes this to FooInputStream, which extends
InputStream and implements read() by calling getByte() on BH.

What i did to test was:
- run the server
- client A wraps the FooOutputStream in a PrintWriter, and
println("foo") is called on it
- client B wraps FooInputStream in a InputStreamReader, which is
then wrapped in a BufferedReader, and readLine() is called on that

The data then goes, one byte at the time, from client A to client B.
Client A stops running, but Client B just sorta hangs around... in a
deadlock i presume. I can make it return and print out the read line
by doing one of two things:
- kill the server
- manually send a -1 to client B

When i've used streams before, i didn't have to send a -1 in order to
get the reading side to get on with it - it just happened magically. I
also don't understand why killing the server make things better...

Can anyone explain this or, as an alternative, suggest a better way to
exchange bytes via RMI. I just really wanted to make streams work. :)

Oh, another thing. To make the server available, i've made it Runnable
and in the run i have a while(true) loop, that makes the thread sleep
for a chunk of time. Maybe that is a problem, too?

Regards,
Carsten H. Pedersen
----------- SOURCE BELOW -------------
package streams.holder;

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface RemoteByteHolder extends Remote {
int getByte() throws RemoteException;
void putByte(int b) throws RemoteException;
}

....

package streams.holder;
import java.rmi.RemoteException;

public class ByteHolder implements RemoteByteHolder {

private int theByte;
private boolean stored = false;

public synchronized int getByte() throws RemoteException {
while(!stored) {
try {
wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

System.out.println("hb: get: "+theByte);
int i = theByte;
stored = false;
notifyAll();
return i;
}

public synchronized void putByte(int b) throws RemoteException {
while(stored) {
try {
wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

System.out.println("bh: put: "+b);
stored = true;
theByte = b;
notifyAll();
}

}
Feb 19 '06 #1
2 2911

"Carsten H. Pedersen" <no@nono.no> wrote in message
news:43***********************@dreader2.cybercity. dk...

I posted earlier under the title "Double streams", where i wanted to use
an RMI object as a sort of proxy for two clients to exchange data via
streams. I kinda failed, but now i'm trying something new. This doesn't
work either, but this time i think someone might be able to solve it,
since i'm not adept at using threads and i think that's where the problem
is. :)


If you don't get any answers for 1 or 2 days, try posting this to
comp.lang.java.programmer. There's a lot of people there who are familiar
with threading who don't read this newsgroup.

If you post there too early though, you get accused of multiposting.

- Oliver

Feb 20 '06 #2
Hi Carsten,

What does your readLine code look like?

Are you doing something like:

while ((line = readLine())!=null) ...
"Carsten H. Pedersen" <no@nono.no> wrote in message
news:43***********************@dreader2.cybercity. dk...
I apologize in advance for the length of the note, and the source code
included.

I posted earlier under the title "Double streams", where i wanted to use
an RMI object as a sort of proxy for two clients to exchange data via
streams. I kinda failed, but now i'm trying something new. This doesn't
work either, but this time i think someone might be able to solve it,
since i'm not adept at using threads and i think that's where the problem
is. :)

The source for ByteHolder and RemoteByteHolder is included below. A server
is run, making a ByteHolder, BH, available via RMI.

Client A obtains the reference to BH, and passes this on to its
FooOutputStream, which extends OutputStream and implements the write(int
b) method by calling putByte(b) on BH.

Client B also gets BH, passes this to FooInputStream, which extends
InputStream and implements read() by calling getByte() on BH.

What i did to test was:
- run the server
- client A wraps the FooOutputStream in a PrintWriter, and println("foo")
is called on it
- client B wraps FooInputStream in a InputStreamReader, which is then
wrapped in a BufferedReader, and readLine() is called on that

The data then goes, one byte at the time, from client A to client B.
Client A stops running, but Client B just sorta hangs around... in a
deadlock i presume. I can make it return and print out the read line by
doing one of two things:
- kill the server
- manually send a -1 to client B

When i've used streams before, i didn't have to send a -1 in order to get
the reading side to get on with it - it just happened magically. I also
don't understand why killing the server make things better...

Can anyone explain this or, as an alternative, suggest a better way to
exchange bytes via RMI. I just really wanted to make streams work. :)

Oh, another thing. To make the server available, i've made it Runnable and
in the run i have a while(true) loop, that makes the thread sleep for a
chunk of time. Maybe that is a problem, too?

Regards,
Carsten H. Pedersen
----------- SOURCE BELOW -------------
package streams.holder;

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface RemoteByteHolder extends Remote {
int getByte() throws RemoteException;
void putByte(int b) throws RemoteException;
}

...

package streams.holder;
import java.rmi.RemoteException;

public class ByteHolder implements RemoteByteHolder {

private int theByte;
private boolean stored = false;

public synchronized int getByte() throws RemoteException {
while(!stored) {
try {
wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

System.out.println("hb: get: "+theByte);
int i = theByte;
stored = false;
notifyAll();
return i;
}

public synchronized void putByte(int b) throws RemoteException {
while(stored) {
try {
wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

System.out.println("bh: put: "+b);
stored = true;
theByte = b;
notifyAll();
}

}

Mar 1 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Duncan Grisby | last post by:
Hi, Does anyone know of a deadlock detector for Python? I don't think it would be too hard to hook into the threading module and instrument mutexes so they can be tested for deadlocks. I've...
8
by: Anita | last post by:
Hi All, Can multiple updates on one table using single query generate deadlock ? For example, at the same time, there are 2 users run 2 queries as follows : User1 runs : update tab1 set...
7
by: Andrew Mayo | last post by:
Here's a really weird one for any SQL Server gurus out there... We have observed (SQL Server 2000) scenarios where a stored procedure which (a) begins a transaction (b) inserts some rows into...
3
by: Nigel Robbins | last post by:
Hi There, I'm getting a deadlock when I have two clients running the following statement. DELETE FROM intermediate.file_os_details WHERE file_uid = ? AND obj_uid There is a compound index on...
8
by: mk | last post by:
You probably suspect the answer, typically its 'yes' deadlock can occur in any multithreaded application. Even ones that employ static members. Commonly it occurs when more than one thread tries...
15
by: Zeng | last post by:
Hi, The bigger my C# web-application gets, the more places I need to put in the tedious retrying block of code to make sure operations that can run into database deadlocks are re-run (retried)...
8
by: Joe Weinstein | last post by:
Hi. create table joe(c1 integer not null, c2 integer not null) Two sessions: Session 1: BEGIN TRAN insert into joe (c1,c2) values (1,2)
13
by: Jonathan Amsterdam | last post by:
I think there's a slight design flaw in the Queue class that makes it hard to avoid nested monitor deadlock. The problem is that the mutex used by the Queue is not easy to change. You can then...
3
by: ThunderMusic | last post by:
Hi, We have a web application developped in asp.net (I think it's not relevant, but well, it's so you know)... Yesterday, we received the following message "Transaction (Process ID 69) was...
3
by: Arun Srinivasan | last post by:
Please correct me if I am wrong 1. no 2 processes can have exclusive lock on same object (by object, same row or same table) 2. on deadlock incident between 2 processes only one of them will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.