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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:44:52+00:00 2026-06-04T23:44:52+00:00

I want to call the add function of an HashSet with some delay, but

  • 0

I want to call the add function of an HashSet with some delay, but without blocking the current thread. Is there an easy solution to achieve something like this:

Utils.sleep(1000, myHashSet.add(foo)); //added after 1 second
//code here runs immediately without delay
...
  • 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-04T23:44:53+00:00Added an answer on June 4, 2026 at 11:44 pm

    You can use ScheduledThreadPoolExecutor.schedule:

    ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor(1);
    
    exec.schedule(new Runnable() {
              public void run() {
                  myHashSet.add(foo);
              }
         }, 1, TimeUnit.SECONDS);
    

    It will execute your code after 1 second on a separate thread. Be careful about concurrent modifications of myHashSet though. If you are modifying the collection at the same time from a different thread or trying to iterate over it you may be in trouble and will need to use locks.

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

Sidebar

Related Questions

I want to create a function so that i can call add JLabel 's,
After ul tag i want to call function in javascript to add list item
When I add something of the class myClass I want to call a function
I want to call an URL in the unload-Function of a Webpage but in
If I want to call a javascript function after some code has been run
I want to call a function a number of times providing it with different
I want to call a function which is in another php class that I
I want to call function with arguement periodically. I tried setTimeout(fnName(),timeinseconds) ; and it
i have an ajax function(with arguments) and i want to call it via html
i am new to objective c programming I want to call a function within

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.