• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Socket Server only processing one request, then it just queues them up

 
Ranch Hand
Posts: 39
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, I have to code to java 1.4 as that is the version available on our systems (Can't upgrade). So I created an application that monitors several things at once on our systems and am in the processing of creating a server that will listen for socket connections from this application to post that information in a JTextArea(Using System.out.println(); for testing). I used most of the code available here (I'll repost it here for clarity) InFormit.

The following is the code I used to create the server.


The request queue


The thread requester



and finally the interface




Now I start it all from main and my package is name popup2

ALL THE CODE AFTER THIS POINT IS HAND JAMMED. I have no way of moving it over via copy/paste



There is more going on in main, but all it does is start various threads based on information that it reads from a config. These threads are what reports to the server, I'll give an example of one. The next part is where I implement RequestHandler


Here is my output flusher. It's a class that I created to send a string from one of my other classes to the output socket.



And finally here is an example of a class that is sending information to the FlushOutput class, multiple threads of these will be opened and connected to the abstract server on an as needed basis. The parser is actually about 250 lines of code, but I'll just post the relevant part here. The final product of most of the code is irrelevant other than it's a String.




So what happens when I run this is everything compiles and runs as expected with one little problem. It prints the first thread to call FlushOuput to the Request handler then nothing. I get messages to my terminal that look like this:

Recieved a new connection from "hostname": hostname
Found an available thread!
Shutting down....
Shutting down the request threads...
[0]: Attempting to kill thread
[1]: Attempting to kill thread

When it should look like this and it does for the first instance after that it just repeats the previous lines over and over.

Recieved a new connection from "hostname": hostname
Found an available thread!
Shutting down....
Shutting down the request threads...
[0]: Attempting to kill thread
[1]: Processing Request...
[1]: Attempting to kill thread
[0]: Thread shutting down...
[In the READER]
[1]: Finished Processing Request
[1]: Thread shutting down




 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow. Excellent start post.

But I think the networking part is irrelevant, and the main issue is thread-related. That's why I'm going to move this thread to our Threads and Synchronization forum.
 
Charles Burton
Ranch Hand
Posts: 39
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I was hoping that I got it right =). This problem as had me banging my head against the wall for a couple of days now.
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the output, it looks like "Shutting down..." gets printed, and that the request queue gets shutdown. This would kill the working threads and prevent requests from being processed. As far as I can see, the only way that you can get to the Shutting down... output (and queue#shutdown()) is to have the running flag in the server set to false, which in turn looks like only happens when the stopServer() method is called. So it looks like something is calling stopServer(), perhaps before you want it to. None of the code you show actually calls that method. So how does the server get shut down?
 
Charles Burton
Ranch Hand
Posts: 39
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks! I commented out the line this.requestQueue.shutdown(); at the end of the AbstractServer class. It now behaves as expected, however I've been working on it for a little too long today and can't tell if that's going to create issues with the queue filling up over time.
 
Ranch Hand
Posts: 443
3
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shouldn't running be volatile or start / stop synchronized (just quickly scanned the code by eye) for "happens before ordering" , inter thread visibility of running.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic