aspose file tools*
The moose likes Java in General and the fly likes Need to change value in HashMap automatically Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Need to change value in HashMap automatically" Watch "Need to change value in HashMap automatically" New topic

Need to change value in HashMap automatically

Sunny Kumar Kalra

Joined: Oct 10, 2010
Posts: 15
Hi All,

I have a requirement , where a HashMap has some keys and values. To be more specific values are either "true" or "false", I need to change theses values i.e from "true" to "false" or vice versa depending on the time.

Like If there has been more than 30 minutes since the "false" value was inserted , so it should now change to "true" (and vice versa).

I know it can be achieved by a Thread, but is there any other way it can be done , may be through some Java API ???

Saikat Mukherjee

Joined: Mar 06, 2008
Posts: 13
Have you tried the quartz schedler.

link to url
Tony Docherty

Joined: Aug 07, 2007
Posts: 1939
All techniques will use a Thread. If you mean you don't want to create your own background thread and handle the delays yourself etc you could use a java.util.Timer.
For each entry you want to flip every 30 minutes add a TimerTask to the timer. If you want to continue flipping that entry every 30 minutes you can choose either fixed rate or fixed delay depending on your requirements.
It is sorta covered in the JavaRanch Style Guide.
subject: Need to change value in HashMap automatically
Similar Threads
Which Design Pattern and how to design using OOP this scenaria
Auto boxing confusion
XSSFFormulaEvaluator evaluate() method
What it means when someone says that "it is too much expensive operation"
Garbage Collection Doubt