Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > Pro Java
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Pro Java Expert level Java questions not about a specific book. Please indicate your version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro Java section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Display Modes
  #1 (permalink)  
Old July 8th, 2008, 05:06 AM
Registered User
Join Date: Aug 2003
Location: Nottingham, , United Kingdom.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Implementing a Queue Server Listener


Added this to 'Beginning Java' but no replies:

Iím implementing a queue Server using a Stack which has class instances as items within the queue. Each object item implements the Runnable interface and run's a specific task. The problem that Iím facing is if I add Ďobject 1, 2, 3 and 4í to the queue (in that order)

(queue becomes)
Element 0 = object 1 (running)
Element 1 = object 2 (running)
Element 2 = object 3 (running)
Element 3 = object 4 (running)

and object 2 and 3 finish whist 1 and 4 are still running

(queue is)
Element 0 = object 1 (running)
Element 1 = object 2 (stopped running)
Element 2 = object 3 (stopped running)
Element 3 = object 4 (running)

then I need objects 2 and 3 to fire an event to the Queue Server to tell it to remove objects 2 and 3.

(queue should now become)
Element 0 = object 1 (running)
Element 1 = object 4 (running)

Iím not sure if the queue server will need more than one thread and needs to wait();

See below snippet code (note: RunCommandGUI could be the objectís 1,2,3 or 4)

public class QueueServerThread implements Runnable {
    protected Thread objrunner = null;
    protected static Stack <RunCommandGUI>queue;

synchronized public void run() {
      Thread thisThread = Thread.currentThread();

        System.out.println("run executed");
        while (this.objrunner == thisThread) {
            try {
                System.out.println("Queue server asleep ");
                this.runsomeChecks(...); //.....
                System.out.println("Queue server now awake\n");

            catch (InterruptedException ie) {

            catch (NullPointerException ne) {
               catch (Exception ie) {
        System.out.println("Queue server Stoppedď);

protected boolean pushOntoQueue () {
        RunCommandGUI obj_rungui = null;

        try {
                for (int i = 0; i < 5; i++) {
                    obj_rungui = new RunCommandGUI(ďobject Ē + (i+1) );
                    synchronized (this.queue) {
            return true;
        catch (Exception e) {
            return false;

public class RunCommandGUI extends javax.swing.JFrame implements Runnable {

Thread objrunner = null;

public void start() {
        if (this.objrunner ==null) {
            this.objrunner = new Thread(this);
            System.out.println("....Starting thread: " + this.objrunner.getName());

 public void run() {
        Thread thisThread = Thread.currentThread();
        while (this.objrunner == thisThread) {
            try {
                System.out.println("Asleep for XX seconds\n");
                System.out.println("thread now awake\n",true);
       if (this.performATask()) {
                     this.objrunner = null;
        // Some how tell Queue Server that this objectís thread has now been terminated so take it out of the queue.
            catch (InterruptedException ie) {
            System.out.println("InterruptedException: " + ie.getMessage().toString());

    private Boolean performATask() {


Can anyone help or advise? Iím currently running Windows XP pro with java 1.6

Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
broken pipe error in implementing client -server octavius BOOK Beginning Linux Programming, 3rd Edition 1 December 17th, 2011 12:42 PM
Implementing a Queue Server Listener pdistant Java Basics 0 July 3rd, 2008 06:17 AM
Help needed implementing shopping cart on server jon1 ASP.NET 2.0 Basics 0 November 17th, 2006 09:33 PM
XML Listener rodmcleay VB How-To 2 June 25th, 2003 08:58 PM

All times are GMT -4. The time now is 10:26 PM.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.