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 5838363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:27:36+00:00 2026-05-22T11:27:36+00:00

I have a java app with two different threads that does the following thing:

  • 0

I have a java app with two different threads that does the following thing:

1.The first thread(which is a ThreadPool)- Listens to one port for incoming connections from five different users.

Let’s call them :

user1 user2 user3 user4 user5

each of them sending GPS data.

2.The second thread
In the same time my java app listens to a second port where waits for another client(different from those who send GPS data) to connect to it.

Now…I have a second app that connects to the java app that I’ve just described it.

In this second app I have a list user1…user5 and depending on which item I will choose(user1…5) I have to receive the correct data from the user I pick.
Also all this data will be stored at the second user in a DB.

Now can anyone give me a hint of how could I share all this data between the threads ????

I tried with Singleton classes and also with BlockingQ but seems none of these are suitable cause the data gets lost!

  • 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-05-22T11:27:36+00:00Added an answer on May 22, 2026 at 11:27 am

    Concurrent execution in Java generally rely on “shared memory” so just make sure the code in the two threads share a reference to a common data structure in which they can exchange information.

    All you need to make sure is that the access to this structure is done in a synchronized / thread safe manner. This can be done manually by using the synchronized keyword (not recommended) or by using classes from the java.util.concurrent package (recommended).

    A BlockingQueue would probably suit you well. What problems did you have when you tried this class?

    The thing is that the thread that reads from the BlockingQueue needs to differentiate between the data that is written in the BlockingQ(data that comes from user1,2,3…).

    I suggest you create a class for UserData which contains both the data and which user it came from. (And store it in a BlockingQueue<UserData>.)

    How long and how much data can a BlockingQ keep????Because all this data needs to be stored in a DB in my second app…so I can afford losing any of it!!!!!!!!!!!

    The BlockingQueue is actually an interface, but all standard implementations of it (ArrayBlockingQueue, LinkedBlockingQueue…) can all keep an arbitrary ammount of data (i.e., are limited only by the ammount of free memory on your computer).

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

Sidebar

Related Questions

I have an application in java that uses two different threads.And for sharing data
I have two java files. In the first I have my activity which starts
Is there a way to have two different Java code for one Android app?
I have a java app that uses log4j. Config: log4j.rootLogger=info, file log4j.appender.file=org.apache.log4j.DailyRollingFileAppender log4j.appender.file.File=${user.home}/logs/app.log log4j.appender.file.layout=org.apache.log4j.PatternLayout
I have a Java app that can authenticate to LDAP by logging users into
I'm have a Java app that also runs as an applet. The app also
I have a standalone Java app that has some licensing code that I want
I have a large Java app that is split up into multiple projects. Each
I have done simple java app for blackberry, while building am getting following error.
I'm using eclipse, and I have two android projects which have different topics. And

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.