D
Danny
Java Gurus:
The method below is called in a meeting application. It lives in a
Tomcat server thread, where it uses a
blocked thread to wait for up to 30 seconds to return an event. When
another thread posts an event for an attendee, it executes a notifyall
on the attendee.
Are there any holes? For example, what can I do to avoid changes to
the attendee, which was being waited upon, between the time the wait
was broken by the notifyall and the attendee is synchronized to
extract and reset its event?
Thanks very much for any advice,
Danny
=========================================================
public ArrayList<MeetingEvent> getMeetingEvents(String[]
session,
Meeting meeting){
ArrayList<MeetingEvent> events = null;
Attendee attendee = null;
synchronized(attendees){
attendee = attendees.get(session
[ServerUtil.MEMBERSHIP_ID] + "." +
meeting.meetingID + "." + session[ServerUtil.USER_ID]);
}
if( attendee != null ){
if( attendee.events.size() == 0 ){ //If
attendee has no events,
wait for 30 seconds.
try{
synchronized(attendee){
attendee.wait(30000);
}
}
catch (InterruptedException ignored){}
}
synchronized(attendee)
{ //If attendee has events save for the
return and empty for next event.
events = attendee.events;
attendee.events = new
ArrayList<MeetingEvent>();
}
}
return events;
} //End getMeetingEvents
Where MeetingEvent is:
public class MeetingEvent implements IsSerializable{
public int action;
public String[][] value;
public String membershipID;
public String meetingID;
public MeetingEvent(String membershipID, String meetingID, int
action, String[][] initialValue){
this.membershipID = membershipID;
this.meetingID = meetingID;
this.action = action;
value = initialValue;
}
public MeetingEvent(){}
}
The method below is called in a meeting application. It lives in a
Tomcat server thread, where it uses a
blocked thread to wait for up to 30 seconds to return an event. When
another thread posts an event for an attendee, it executes a notifyall
on the attendee.
Are there any holes? For example, what can I do to avoid changes to
the attendee, which was being waited upon, between the time the wait
was broken by the notifyall and the attendee is synchronized to
extract and reset its event?
Thanks very much for any advice,
Danny
=========================================================
public ArrayList<MeetingEvent> getMeetingEvents(String[]
session,
Meeting meeting){
ArrayList<MeetingEvent> events = null;
Attendee attendee = null;
synchronized(attendees){
attendee = attendees.get(session
[ServerUtil.MEMBERSHIP_ID] + "." +
meeting.meetingID + "." + session[ServerUtil.USER_ID]);
}
if( attendee != null ){
if( attendee.events.size() == 0 ){ //If
attendee has no events,
wait for 30 seconds.
try{
synchronized(attendee){
attendee.wait(30000);
}
}
catch (InterruptedException ignored){}
}
synchronized(attendee)
{ //If attendee has events save for the
return and empty for next event.
events = attendee.events;
attendee.events = new
ArrayList<MeetingEvent>();
}
}
return events;
} //End getMeetingEvents
Where MeetingEvent is:
public class MeetingEvent implements IsSerializable{
public int action;
public String[][] value;
public String membershipID;
public String meetingID;
public MeetingEvent(String membershipID, String meetingID, int
action, String[][] initialValue){
this.membershipID = membershipID;
this.meetingID = meetingID;
this.action = action;
value = initialValue;
}
public MeetingEvent(){}
}