📄 lazydate.java
字号:
package jsp.tags.dapact.util;
import java.util.*;
/**
* Title: Data Aware Processing And Control Tags
* Description: Tag library for the processing and controlling the input and output of data.
* Copyright:
* Compile Date: @compile_date@
* @author Dov Bulka - Java Performance and Scalability Volume 1: Server-Side Programming Techniques.
* @amp_sign@version @VERSION@
*/
/**
* Class only processes a data into a string every refresh (in milliseconds) - even
* though this will be used by multiple threads, nothing will be synchronized. This means
* that the member data may not be updated correctly, so you should set the refresh
* rate low enough to minimize any problems this might cause you. If you need exact time,
* use the Date class directly.
*
* @author Dov Bulka - Java Performance and Scalability Volume 1: Server-Side Programming Techniques.
*/
public class LazyDate
{
/**
* The default number of milliseconds to refresh the string representation of the
* date and time.
*/
public static final long DEFAULT_LAZY_DATE_REFRESH = 1000;
/**
* Constructor that allows specification of how often to refresh the date.
*
* @param refresh how many milliseconds between refreshing.
*/
public LazyDate(long refresh)
{
cacheRefresh = refresh;
update();
}
/**
* Retrieve a shared instance (creates one version and does not create another
* into resetShared() is called).
*
* @return returns a shared instance of this class.
*/
public static final LazyDate getInstance()
{
return lazyDate;
}
/**
* Retrieve today's date as a string.
*/
public String todaysDate()
{
long now = System.currentTimeMillis();
if ((now-lastCheck) > cacheRefresh)
{
update();
}
return today;
}
/**
* Retrieve today's date as a string with a space a the end.
*/
public String todaysDateWithSpace()
{
todaysDate();
return todayWithSpace;
}
/**
* Update the string representation of the date.
*/
private void update()
{
lastCheck = System.currentTimeMillis();
today = (new Date()).toString();
todayWithSpace = today + " ";
}
private long lastCheck = 0; // Never checked before
private String today;
private String todayWithSpace;
private long cacheRefresh;
private static LazyDate lazyDate = new LazyDate(DEFAULT_LAZY_DATE_REFRESH);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -