0

I am having a Login screen demanding username and password to Login to a desktop application in java.

Now my problem is that suppose their are 2 or more users at the same time using my desktop application.Means their are two or more threads running at one time Now how to ensure that multiple clients access the server concurrently ?

I need to visualise it by printing which thread is running at present time.

So could anyone help me to do this

user3462609
  • 105
  • 2
  • 11
  • You can use some Static Variable for this . There is only one static variable of one class , so it doesn't matters that how many instances You have of your login class. To track the number of users or to track which is online You can use a static variable. static int count; // to track number of users – farhangdon Mar 29 '14 at 16:36
  • @FarhanGDon please could you provide some pseudocode or a bit more explanation ? – user3462609 Mar 29 '14 at 16:45
  • For example if You have a login class . class login{ String username; String password; static int threadNum ; } So the static member will be accessible every where and there is only one static variable for whole class . Other variables are separate for each instance but static is shared by all instances. I hope this may help.. – farhangdon Mar 29 '14 at 16:56

1 Answers1

1

This is same question that you have asked already here Multiple clients access the server concurrently in the same context.

Solution:

Here each client is connected in a separate thread from server and that thread contains all the information about the client. It will solve your concurrency problem as well as you can store any information about the client.

Please have a look at my answer and let me know if you want to do differently here.

Community
  • 1
  • 1
Braj
  • 46,415
  • 5
  • 60
  • 76