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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:53:29+00:00 2026-06-06T02:53:29+00:00

I am new to threads. I want to communicate with multiple sensors at one

  • 0

I am new to threads. I want to communicate with multiple sensors at one time after every minute continuously 24/7.

Senario:
I have a method to talk to the sensors which takes 3 arguments

public String perform(String command, String ip, String port)
{
  //talk to the sensor and then 
  returns reply;
}

I have a database that contains the details of the sensor.

What I’m doing right now

while(true)
{
  //get sensors from database

   //run perform method for all instruments
   for(int i=0;i<sensors.length-1;i++)
   {
    //call perform method and save the reply
   }
   Thread.sleep('one minute');
}

Problem:
The problem is if I have 100 sensors and each sensor takes 1 second to reply then after that I will be waiting for 1 minute, in this case I may lose some information. And to be honest sometime It takes more than a second to respond.

What I want to do is, get the information from the database for all the sensors
then create one thread for each sensor. Then run all the threads at one time which will return me some information. After that wait for one minute then do it again.

Any help is appreciated.

Thanks

  • 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-06T02:53:30+00:00Added an answer on June 6, 2026 at 2:53 am

    Have you looked at the ScheduledThreadPoolExecutor ?

    A simple usage would be to create a Callable for each of your sensors, and configure the thread pool to contain as many threads as you have sensors. Then submit each Callable, specifying an appropriate schedule.

    Note that this approach doesn’t guarantee particularly accurate timings (Java’s not by any means a real-time platform). The other issue is that creating a lot of threads can be relatively memory-hungry (IIRC the standard heap allocation per thread is 512k, but it’s configurable) and this approach wouldn’t scale if you had 1000s of sensors.

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

Sidebar

Related Questions

I want to start some new threads each for one repeating operation. But when
I have a windows form where in I open new threads for server communication.
I am having problems with passing arguments to new threads, I have the following
I have a HttpClient to communicate with my server, and I want to persist
I have a multi-threaded server that handles client requests, and makes new threads for
Alright I am kind of new to threads so I have this question. I
I have a embarrassingly parallel problem that I want to execute on multiple processors.
I want to send new thread in vbulletin forum through the application i made
I want to start a new thread using a C function, not an objective-C
For Create And Start New Threads In C# We Act Like Below : using

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.