[jboss-jira] [JBoss JIRA] (JGRP-1881) TimeService: provide time on request
Bela Ban (JIRA)
issues at jboss.org
Fri Sep 5 02:43:59 EDT 2014
[ https://issues.jboss.org/browse/JGRP-1881?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Bela Ban updated JGRP-1881:
---------------------------
Description:
Currently the TimeService registers a task that runs every (say) 500 ms. It gets the current time and updates a field. Threads which get the time from the TimeService get the value of that field, so {{System.currentTimeMillis()}} is not called too much.
However, when no thread needs to get the time for a period of time, the TimeService nevertheless calls {{System.currentTimeMillis()}} every 500 ms, and we have an additional task in the timer.
h5. SOLUTION
* Remove that task which periodically gets the current time
* Add a {{timestamp}} field ({{System.nanoTime()}}) which gets set when {{System.currentTimeMillis()}} is called
* Add a field {{current_time}} which is set by {{System.currentTimeMillis()}}
* When a thread wants to get the current time from the TimeService, it compares the current time with the timestamp and, if 500 ms have elapsed, calls {{System.currentTimeMillis()}}, sets the timestamp and current_time fields and returns the time
* If the time elapsed since the last update is less than 500 ms, it returns {{current_time}}
There has to be synchronization around getting the current time ({{System.currentTimeMillis()}}), but this could be done with a CAS and a busy loop.
was:
Currently the TimeService registers a task that runs every (say) 500 ms. It gets the current time and updates a field. Threads which get the time from the TimeService get the value of that field, so {{System.currentTimeMillis()}} is not called too much.
However, when no thread needs to get the time for a period of time, the TimeService nevertheless calls {{System.currentTimeMillis()}} every 500 ms, and we have an additional task in the time.
h5. SOLUTION
* Remove that task which periodically gets the current time
* Add a {{timestamp}} field ({{System.nanoTime()}}) which gets set when {{System.currentTimeMillis()}} is called
* Add a field {{current_time}} which is set by {{System.currentTimeMillis()}}
* When a thread wants to get the current time from the TimeService, it compares the current time with the timestamp and, if 500 ms have elapsed, calls {{System.currentTimeMillis()}}, sets the timestamp and current_time fields and returns the time
* If the time elapsed since the last update is less than 500 ms, it returns {{current_time}}
There has to be synchronization around getting the current time ({{System.currentTimeMillis()}}), but this could be done with a CAS and a busy loop.
> TimeService: provide time on request
> ------------------------------------
>
> Key: JGRP-1881
> URL: https://issues.jboss.org/browse/JGRP-1881
> Project: JGroups
> Issue Type: Enhancement
> Reporter: Bela Ban
> Assignee: Bela Ban
> Fix For: 3.6
>
>
> Currently the TimeService registers a task that runs every (say) 500 ms. It gets the current time and updates a field. Threads which get the time from the TimeService get the value of that field, so {{System.currentTimeMillis()}} is not called too much.
> However, when no thread needs to get the time for a period of time, the TimeService nevertheless calls {{System.currentTimeMillis()}} every 500 ms, and we have an additional task in the timer.
> h5. SOLUTION
> * Remove that task which periodically gets the current time
> * Add a {{timestamp}} field ({{System.nanoTime()}}) which gets set when {{System.currentTimeMillis()}} is called
> * Add a field {{current_time}} which is set by {{System.currentTimeMillis()}}
> * When a thread wants to get the current time from the TimeService, it compares the current time with the timestamp and, if 500 ms have elapsed, calls {{System.currentTimeMillis()}}, sets the timestamp and current_time fields and returns the time
> * If the time elapsed since the last update is less than 500 ms, it returns {{current_time}}
> There has to be synchronization around getting the current time ({{System.currentTimeMillis()}}), but this could be done with a CAS and a busy loop.
--
This message was sent by Atlassian JIRA
(v6.3.1#6329)
More information about the jboss-jira
mailing list