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

  • Home
  • SEARCH
  • 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 8487385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:13:20+00:00 2026-06-10T21:13:20+00:00

On my Client/Server Desktop application. I have this problem of how I should properly

  • 0

On my Client/Server Desktop application. I have this problem of how I should properly code my JDBC class with my Models to ensure all persistence request can support concurrency. i.e., multiple models want to request update to its persistence counterpart simultaneously [without atmost delay].

The scenario goes like this. Following the classes located in the server application.

Persitence Package:

abstract class AbstractService {
  // other fields
  private final String tName, tId;
  private final String sqlStatement;
  public AbstractService(final String tName, final String tId) {
    this.tName = tName;
    this.tId = tId;
    this.sqlStatement = ""; // SELECT statement
  }
  // java.sql.Connection() createConnection()
  // methods
}
public class T1Service extends AbstractService {
  private final String sqlDMLStatements;
  public T1Service() {
    super("t1", "t1Id");
    this.sqlDMLStatements = ""; // other DML statements
  }      
  // methods having return types of List<E>, Object, Boolean, etc.
  // i.e., public List<E> listAll()
}

Communication class [Client class]

import java.net.*;
import java.io.*;
public class Client extends Observable{
  private Socket socket;
  private ObjectInputStream input;
  private ObjectOutputStream output;
  private Object message;
  // Constructor
  // Getters/Setters
  // Other methods like open or close input/output
  private class ReceiverRunnable implements Runnable
    @Override
    public void run() {
       while(running) { // if socket is still open and I/O stream are open/initialized
          try { message = input.readObject(); } 
          catch(Exception e) {}
          finally { setChanged(); notifyObservers(); }  
       } 
    }
  }
}

The Main Class [Server class]

import java.net.*;
public class Server {
   private List<Client> clientList; // holds all active connections with the server
   private T1Service    t1Service
   private class ConnectionRunnable implements Runnable {
      @Override public void run() {
         while(running) { // serverSocket is open
           Client client = new Client(ServerSocket.accept(), /* other parameters */);
           client.addObserver(new ClientObserver(client));
           clientList.add(client);
         }
      } 
   }
   private class ClientObserver implements Observer {
      private Client client;
      // Constructor
      public void update(Observable o, Object arg) {
         // Check the contents of 'message' to determine what to reply
         // i.e., message.equals("Broadcast") {
         // synchronized(clientList) {
         //   for(Client element : clientList) {
         //     element.getOutput().writeObject(replyObject);
         //     element.getOutput()..flush();
         //   }
         // }
         // i.e., message.equals("T1") {
         // synchronized(t1Service) {
         //     client.getOutput().writeObject(t1.findAll());
         //     client.getOutput().flush();
         // }
      } 
   } 
}

Since this is a Client/Server applcation, multiple request from the client are simultaneously feed to the server. The server process the request sending the appropriate reply to the approriate client. Note: All of the objects sent between Client & Server an instance of java.io.Serializable.

Having this kind of scenario and looking into the block of Server.ClientServer.update() we may have a performance issue or I should say a delay in processing the N client(s) request due to Intrinsic Locks. But since I have to the rules concurrency and synchronization to ensure that Server.T1Service won’t get confused to the queue of N clients request to it. Here’s are the questions:

  1. According to the Item 1 of Effective Java – Second Edition regarding Static Factory, would this let me create a new class reference to the methods inside the classes of Persistence package?
  2. Would each Client element inside List<Client> would form a concurrency issue having N client update their message field simultaneously triggering the ClientObsver.update() wherein the reference object(s) of this Observer is only a single instance in the parent class. I was avoiding creating multiple instance of T1Service due to memory concerns.
  3. If we are going to go by the contents of Effective Java – Second Edition, how can I convert my persitence class in a way they can be read easily, easily instantiated, and support concurreny?
  • 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-10T21:13:22+00:00Added an answer on June 10, 2026 at 9:13 pm

    Is my theory of [Item 1] Static Factory correct?

    Yes, you can use a static factory instead of constructors. Typically this is when you the construction logic is complex and shared between various subtypes to warrant a factory pattern. Additionally the factory may provide means for dependency injection outside of a DI framework.

    Would it then solve the concurrency issue of the converted static factory global objects?

    If you need to synchronize construction, then a static factory works well, just add synchronized to the method declaration on your factory methods. If you need to synchronize methods on the objects themselves then this will not help.

    Is it advisable for me to convert to static factory if where dealing with concurrent access to a global object and where wanted real-time access to the methods of each global object?

    As I answered above, it depends on what you are trying to achieve. For constructor synchronization use a factory.

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

Sidebar

Related Questions

we have an AIR application which is running in client-server mode as a desktop
I have implemented a client-server transferring from Windows desktop application to iPhone App. I
I currently have a Firebird server on Windows and Windows desktop client applications for
I want to develop a client-server based desktop application using .Net 4, C# and
I am testing one Desktop based client server application. I want to perform a
I'm developing a client-server application and have been tasked with adding support for running
I am developing a windows desktop client/server application in .NET where the client application
I'm working on a server written in Java, and a client (a desktop application
I am building a client-server based solution; client being a desktop application and the
I have a client-server application - wherein the server is essentially an ASP .NET

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.