0 Replies Latest reply: Jan 28, 2008 6:05 AM by 807581 RSS

    Problem with threads!!!

      Hi Folks

      Hopefully someone can give me a little help on this...

      I have an app that sits inside the Sun Java System Application Server. I also have a client that connects to a FTP server, downloads files and passes these on, one at a time to the server for processing. I have to wait on the results of the processing coming back from the server to the client before I can decide what to do with this file, and before I can process the next one....

      I thought this was a little wasteful as I wasnt taking advantage of the Server's multi-threading capabilites so I ive done this...

      Broke my client into two classes (FtpClient, FtpProcess) - both implementing the Runnable interface and also using the Observed/Observable pattern.

      FtpClient creates downloads the files from the FTP Server and places these on a QUEUE. It also creates an array of FtpProcess.

      sample code below..
      public void run() {
           long start = populateQueue();
      FtpProcess's creates a SessionBean to be able to talk to the app on the server while its run( ) method polls the QUEUE and when there is something on it, it returns the top of the queue and calls bean.processFile(file)....

      sample code....
      public void run() {
          while (mJobsToDo == true) {
              synchronized (mQueue) {
                  while (mQueue.isEmpty()) {
                      try {
                      } catch (InterruptedException e) {}
                  file = mQueue.poll();
              if (file != null) {
                  System.out.println("[" + this.mName + "] got file [" + file.getFilename() + "] from Queue");
                  try {
                      mFPS = mBean.processFile(file);
                      catch (RemoteException e) {
                  } else {
                      System.out.println(this.getName() + "got NULL File");
      This file seems to be getting trampled on somewhere on the server and i cant figure out why or where... All operations on the QUEUE are synchronized (both putting and getting)...

      If I dont go to the server, ie. replace
      mFPS = mBean.processFile(file);
          mFPS = new FileProcessingStatus();
      everything is fine so I dont think there's a problem with my thread code or synchronization as each thread gets a different file of the queue each time...

      Can someone please help... Thanks in advance