Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7805025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:05:30+00:00 2026-06-02T02:05:30+00:00

My application basically uses apache’s httpclient to connect to a server and do something

  • 0

My application basically uses apache’s httpclient to connect to a server and do something for the user.

I am a java beginner (though not a development beginner), so many java specific approaches may have been calmly ignored.

DESCRIPTION

  • the app uses a TrayIcon with a popup menu as the only user interface and reacts with either tray messages or popup [confirm] dialogs.
  • it uses threads because the httpclient was effectively blocking the main thread when waiting for a response
  • employs a client-server to assure a single instance only and reactions to second instance attempts
  • employs observer/observable pattern to react to the httpclient’s and the single instance watchdog server’s messages
  • the main behavior is controlled by a Controller class, which is the only Observer; everything related to the httpclient is in a separater WebClient class, which implements Runnable and extends Observable; then there’s the AttServer which is again Runnable and Observable and controls everything around the server listener (there’s not much actually).

This is my first application in Java, so many obscurities are possible..:(

PROBLEM

The desired behavior is that whenever a user attempts to run a second instance of this app, then it tries to bind a socket listener on port X and, failing, sends a string message to that port. The ‘main’ app accepts the message and reacts with a confirm dialog being shown asking the user for some input.

Everything was working just fine up to the point when I’ve added the client-server; the second instance successfully triggers the update() method of the observer, the observer correctly distinguishes what’s going on and fires the corresponding method; and then at the point of the first new GUI component (a confirm dialog) should show up, NOTHING happens:

  • the app doesn’t do anything
  • no errors or exceptions thrown in System.out
  • the tray icon CONTINUES to work just fine (right click shows a menu etc)

..it’s just that all the instructions coming after the dialog doesn’t get executed and the dialog doesn’t show up.

WEIRDNESS #1

When the user uses the tray icon menu to fire some other command that shows a dialog, the GUI somehow coughs up and shows BOTH (or more when appropriate) dialogs in the correct order (first the stuck hidden dialog shows up and then the second fresh one) and everything just seems that this is the correct state and all commands get executed correctly (albeit some of them ‘a bit’ later).

WEIRDNESS #2

I guess this is caused by the swing being not really compatible with threads; however, when the update() method gets fired up from the httpclient (which is a separate thread as well), the GUI works just fine. The only difference in the way the Observer gets notified is that the WebClient calls the notifyObservers() after some user action (albeit in a separate thread and after (at worst) 30s timeout and the AttServer calls notifyObservers() in a catch() block, because IOException is thrown when the specified port has been already bound.

WEIRDNESS #3

This problem is irregular to say the least. It USUALLY occurs in the development environment (netbeans), although sometimes it doesn’t — at first I’ve got the impression it was solved by calling another (dummy) JDialog, which remained hidden intentionally, before the actual problematic dialog — it seemed that swing needed a little ‘nudge outta the door’; though after building the project into a jar or an exe (via launch4j), the problem was back. Then I’ve tried to use a single JFrame component for ALL the swing dialogs and it helped somehow — sometimes when the output jar is run it works as it should and the next day it hides dialogs again.

I am totally lost, scoured the Earth for a solution, found nothing really. I hope that somebody else might bump into some similar problem and, being a more experienced Javaman, found a solution. I’ve also tried some doLayout(), validate(), revalidate(), repaint(), update() calls on the main JFrame instance, but no go.

There’s hope 🙂 Thanks for reading and thanks even more for any ideas.

CODE EXAMPLES

This is the run() function from AttServer — the source of the non-working update()s.. (it’s a bit hard coded as the main functionality is there and I got stuck elsewhere..)

public void run() {

    this.addObserver( Controller.getInstance() );

    setChanged();

    // this.command == INIT set and new thread with AttServer called in the beginning of the main()
    if( null != this.command ) {

        switch( this.command ) {
            case INIT:
                try {
                    init();
                } catch( IOException ex ) {
                    notifyObservers( new ErrorEvent( 100 , "Could not bind the specified port." ) );
                }
            break;
            default:
        } //switch

    // no command, looks like an incoming connection
    } else {

        try {
            DataInputStream in = new DataInputStream( socket.getInputStream() );

            String inputLine;

            while( ( inputLine = in.readLine() ) != null ) {

                if( inputLine.trim().equals( EventType.CLOCKIN.toString() ) ) {

                    notifyObservers( EventType.CLOCKIN );

                    return;
                }
            }
        } catch( IOException ex ) {
            //todo
        }
    }
}

..this is the opposite side of the fence, the update() method:

public void update( Observable obj, Object arg) {
    // received a remote request *******************************************
    if( obj instanceof AttServer
        && arg instanceof EventType ) {

        EventType command = (EventType) arg;

        Attendance.debugMsg( "Received " + command.toString() + " request from AttServer" );

        if( false == isOnClock ) {
            doClock( true , true );
        }
    } // ..........

.. and this is the essence of the doClock() method called from update() — there’s nothing really, and even when the dialog is shown right after the call, or event when it’s shown right in the update() method, it doesn’t work.

(overloaded with default data)
public static void doClock( Boolean clockIn , Boolean confirm , String message , String title ) {

    Event lastEvent = Log.getLastClock();

    if( confirm ) {
        if( JOptionPane.NO_OPTION == JOptionPane.showConfirmDialog( mainFrame , message , title , JOptionPane.YES_NO_OPTION ) ) {
            return;
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T02:05:31+00:00Added an answer on June 2, 2026 at 2:05 am

    Without reading through this whole document (!!!) I would guess that you are not updating the GUI via the Event Dispatch Thread (EDT).
    The GUI is supposed to be updated only by a single thread, the EDT.
    You can have background threads in your applications, but the update of the GUI must be passed to be done to the EDT only.
    Do not touch any Swing control in a thread of your own i.e. other than EDT.
    Otherwise you will have tons of problems.
    It is plainly wrong not to go through the EDT

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Android Application which is basically uses WebView for all interaction.. How
I need to write cross platform application (basically CRUD). Is usage of Java Swing
I'm using Valgrind --tool=drd to check my application that uses Boost::thread. Basically, the application
Basically i am trying to build an application that uses SSIS to run a
I am busy with an application that uses transclusion. Basically I need to parse
I'm building a client-server (c#) application that uses a web services to synchronize the
I'm currently working with a part of my application that uses Dynamic Web User
I have an Zend–based application that uses long polling. Basically it makes a HTTP
Basically, I have a server and mobile application . Mobile application subscribes on events
I have an application that uses several different Java classes and would like to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.