DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Hybrid View

  1. #1
    Satish Guest

    wait() notify() problem

    Pls have a look at the code below, when I am trying use wait() and notify()methods
    , I am getting IllegalMonitorStateException saying that the current thread
    is not owner..what odes it mean and how do I rectify the problem ???

    import com.logica.omg.psa.PsaBindRequest;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.io.IOException;
    import java.net.Socket;
    import java.net.UnknownHostException;
    import java.net.SocketException;

    public class PsaSocketNode {

    private final String host = ""; // JENNY the machine on
    // the PSA Server is running
    private final int port = 3535; //
    private static Socket psaSocket;
    private InputStream inStream;
    private OutputStream outStream;
    private PsaBindRequest psaBindRequest;
    private PsaBindResponse psaBindResponse;
    private byte initFrame;
    private byte control; // bind/unbind or transaction traffic
    private byte service;
    private byte version;
    private long transactionId;
    private byte operation;
    private byte transactionResult;
    private byte transCompRetryPadding; //transaction component + retry +
    private byte accIndOperParams;
    private SMEAddress sourceAddress; //MSISDN
    private SMEAddress destinationAddress; //MDN
    private SMEAddress sourceMSCAddress;
    private SMEAddress destinationMSCAddress;
    private byte ton;
    private byte npi;
    private String msisdn;
    private byte endFrame;
    private byte response;
    private short protocol;
    private byte[] applRequestData = new byte[105];
    private byte[] bindRequestData = new byte[5];
    private byte[] unbindRequestData = new byte[5];
    private static byte[] responseBindData = new byte[6];
    private static byte[] responseUnbindData = new byte[5];
    private static byte[] responseApplData = new byte[16];

    private boolean gotResponse = false;

    /** Default Constructor */
    public PsaSocketNode() {



    public synchronized void sendCommand()
    SendBindRequest sendBindRequest = new SendBindRequest();


    public synchronized void gotResp()

    ReadBindResponse readBindResponse = new ReadBindResponse();

    public void connectToServer() {
    try {
    psaSocket = new Socket(host, port);
    System.out.println("Connected to " + host + " " + "on " + port);
    outStream = psaSocket.getOutputStream();
    inStream = psaSocket.getInputStream();
    catch (UnknownHostException ioe) {
    System.err.println("No local IP address found - is your network
    catch (IOException ie) {
    System.err.println("Could not connect to host - IO exception");

    public byte[] constructBindRequest() {
    this.initFrame = 0x7e;
    this.control = 0x01; // bind request
    this.service = 0x01;
    this.version = 0x01;
    this.endFrame = 0x7e;
    psaBindRequest = new PsaBindRequest(this.initFrame, this.control,
    this.service, this.version, this.endFrame);
    System.out.println("Constructed the bind request object");
    byte[] bindRequestData = psaBindRequest.getByteInformation();
    System.out.println("Converted the data into a byte array");
    return bindRequestData;

    public void sendBindRequest() {
    try {
    bindRequestData = constructBindRequest();
    System.out.println("Got the byte array object reference" + bindRequestData.length);
    //outStream = psaSocket.getOutputStream();
    System.out.println("About to write bind data");
    System.out.println("satish sent the bind request");
    catch (SocketException se){System.err.println("Could not write
    the application data on to socket"); };

    System.out.println("PSA CLIENT : Finished writing bind data on
    to the socket");
    catch (IOException e) {
    System.err.println("Could not write the bind data on to socket
    public void readBindResponse(byte[] responseBindData) {
    try {
    //inStream = psaSocket.getInputStream();
    System.out.println("PSA CLIENT : Got the bind response from the
    initFrame = responseBindData[0];
    service = responseBindData[1];
    protocol = responseBindData[2];
    version = responseBindData[3];
    response = responseBindData[4];
    endFrame = responseBindData[5];
    // This is the byte that has the response value in it.
    if (response == 0) {
    System.out.println("SUCCESSFUL BIND REQUEST");
    System.out.println("Bind Response Code is " + response);
    else {
    System.out.println("UNSUCCESSFUL BIND REQUEST");
    System.out.println("PSA CLIENT : Finished reading the bind response");
    catch (UnknownHostException ioe) {
    System.err.println("No local IP address found - is your network
    catch (IOException ie) {
    System.err.println("Could not read the bind response data from
    the socket");

    class SendBindRequest extends Thread {

    SendBindRequest() {

    public void run() {
    try {
    System.out.println("satish waiting for the response
    to come");
    catch (Exception e) {System.out.println(e.getMessage()); }

    class ReadBindResponse extends Thread {

    ReadBindResponse() {

    public void run() {
    try {
    System.out.println("satish got the bind response");
    gotResponse = true;
    System.out.println("satish notifieed the other thread
    abput reponse");

    catch (Exception e) { System.out.println(e.getMessage()); }

    public static void main(String[] args) {
    PsaSocketNode psaSocketNode = new PsaSocketNode();


  2. #2
    Satish Guest

    Re: wait() notify() problem

    The problem in the code below is wait() and notify() must be used with in
    the synchronized blocks. My problem is rectified now, may be this might help


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.