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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:42:14+00:00 2026-05-11T08:42:14+00:00

In my application, I have the following recurring pattern where I get the feeling

  • 0

In my application, I have the following recurring pattern where I get the feeling that this is an incomplete or warped version of some common pattern that I’m not aware of. In my implementation, I can’t seem to find a good way to implement a particular operation, as described below.

A collection of objects, let’s call them ‘sources’, produces data if you call a method on them. An instance of ScheduledThreadPoolExecutor (from java.util.concurrent) is used to periodically do readings on the sources and put the data on a common outbound queue:

 --o       method calls    +-----+ --o       <--         |  o  |     --->    |||||||||||           -->         | o o | --o      data         +-----+  sources             thread pool          outbound queue 

The sources, the thread pool and the queue are members of a class that provides methods to add sources and to retrieve the head of the queue.

Below is the code to add a new source. I’m wondering what happens if I remove a source from the collection.

public void vAddSource(ISource src) {     this._rgSources.add(src);     final ISource srcT = src;     // q is the outbound queue, which is a private member in the class     // defining this method. Name is abbreviated for readability     Runnable cmd = new Runnable() { public void run() { q.add(srcT.sRead()); } }     // tpx is the thread pool     this._tpx.scheduleAtFixedRate(cmd, 0L, 1000L, TimeUnit.MILLISECONDS); } 

Now, the way Java works – if I got that correctly -, src etc. are object identifiers that get passed around by value, so in the above code there is only one ISource object and an identifier for it gets added to the collection as well as passed into the thread pool. If I remove the identifier from the collection, the object is still there, hence the thread pool will continue to read from it as if nothing happened.

Am I understanding this correctly? And what would be a typical approach if you wanted the thread pool to take note of the removal and also discard the source?

  • 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. 2026-05-11T08:42:14+00:00Added an answer on May 11, 2026 at 8:42 am

    ThreadPoolExecutor (and hence ScheduledThreadPoolExecutor) has a remove(Runnable) method. You might also be interested in FutureTask which can be cancelled (although that wont take it out of the work queue).

    ETA (by Hanno Fietz, from pgras’ answer): This also requires to map the Runnables to a source so that the removeSource method could call ThreadPoolExecutor.remove with the right one.

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

Sidebar

Related Questions

We have a Hibernate/Spring application that have the following Spring beans: <bean id=transactionManager class=org.springframework.orm.hibernate3.HibernateTransactionManager
I have a .net application that is doing COM interop and calling some native
In my winform application I have the following scenario: I want to get multiple
I have following code in my application: // to set tip - photo in
I have following requirement in my application. A tableView with games title After selecting
I have following code in my Application. Comments in my code will specify My
I have following code in my application. [self.navigationController pushViewController:x animated:YES]; It will push a
I have following problem: I have built a tabbar application with 4 tabs. I
I have following requirement, I have C#/.Net console application, which refers to 'System.Data.Sqlite.dll' 'System.Data.Sqlite.dll'
In an ASP.NET MVC application where I have the following model.. public class EventViewModel

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.