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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:55:32+00:00 2026-05-28T15:55:32+00:00

I have an object Producer which internally starts a thread that will listen for

  • 0

I have an object Producer which internally starts a thread that will listen for some network events, and at most times block on a receive() method. In this Producer object I have a WeakHashMap<Integer, Vector<IConsumer>> containing at hash map with keys being the events that the Producer can produce, and the value being a list of consumer that has registered on these events.

Now I have a Main object which constructs some Manager. The Manager the constructs one single Producer and any number of ConcreteConsumers implements IConsumer. The Manager contains a reference to the Producer and the ConcreteConsumers.

Is this a valid construction, will the Vector<IConsumer> not be eligible for GC immediately after insertion in the WeakHashMap<Integer, Vector<IConsumer>> as there are not reference to the actual vector? There are only references to the Producer and the ConcreteConsumers directly. If so, how can I solve this?


Next what happens is that the Main object drops the reference to the Manager, which should cause all the ConcreteConsumers to be eligible for GC, which is what I want.

But, I also want the actual Producer object to be eligible for GC and for the internal thread to stop executing at this point. Any suggestions on how to do this?

  • 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-28T15:55:33+00:00Added an answer on May 28, 2026 at 3:55 pm

    It’s the key in WeakHashMap that has the weak reference. The value is strongly referenced. The entry will be removed some time after there are no strong references to the key, an Integer in this case. That is the very same instance of Integer, not just an instance with the same value. Values types aren’t particularly useful as keys to WeakHashMap.

    (WeakHashMap is not useful as a cache (you want to be using SoftReferences, and probably someone else’s library).)

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

Sidebar

Related Questions

I have a single thread producer which creates some task objects which are then
I have a 'producer' object, that steps through some data and emits various signals
I have two threads, a producer thread that places objects into a generic List
I think I read somewhere that some modules only have object oriented interfaces (
I have a thread which produces data in the form of simple object (record).
I have an object that implements ArrayAccess , Iterator and Countable . That produces
If you have a java.io.InputStream object, how should you process that object and produce
I have object A which in turn has a property of type Object B
I have object A which contains multiple instances of object B, which in turn
I have two tables: object that has object_id column and avalues that have object_id

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.