Using RPC seems ok here. Note that there are no threads in the browser.
Also you cant compare the JProfiler results of the application running
in debug mode to the actually compiled JavaScript application which runs
in the browser engine.
On 17.04.2013 12:31, Bhumika Thaker wrote:
Hi,
I have one gwt application. I have a requirement to show frequently
server date to client side, For this, I used GWTEventService. While
user logged in, then I am sending one rpc and create one thread using
timer which will send periodically event to client.
But due to memory leak, after debugging using *JProfiler *I came to
know that date object created inside timer and due to thread creation
it is not being garbage collected.
I think I am doing somewhat wrong way. Let me know is What is right
approach to send frequently server time to client in GWT?
*This is a method which will call after login.*
public static void *registerServerTimerEvent*(final Label widget,final
String dateFormat)
{
ClientGinjector ginjector = (ClientGinjector)
WorkFlowSessionFactory.getValue(WorkFlowSesisonKey.GININJECTOR);
DispatchAsync dispatchAsync = ginjector.getDispatchAsync();
dispatchAsync.execute(new UtilityCaller(), new
AsyncCallback<UtilityCallerResult>() {
@Override
public void onFailure(Throwable caught) {
}
@Override
public void onSuccess(UtilityCallerResult result) {
String strdate;
if(dateFormat!=null){
DateTimeFormat fmt = DateTimeFormat.getFormat(dateFormat);
strdate = fmt.format(result.getServerDate());
}else{
strdate = result.getServerDate().toString();
}
setDateTime(strdate,widget);
}
});
RemoteEventService theRemoteEventService =
RemoteEventServiceFactory.getInstance().getRemoteEventService();
//add a listener to the SERVER_MESSAGE_DOMAIN
theRemoteEventService.addListener(NTTimerEvent.SERVER_MESSAGE_DOMAIN,
new RemoteEventListener() {
public void apply(Event anEvent) {
if(anEvent instanceof NTTimerEvent) {
NTTimerEvent theServerGeneratedMessageEvent = (NTTimerEvent)anEvent;
String strdate;
if(dateFormat!=null){
DateTimeFormat fmt = DateTimeFormat.getFormat(dateFormat);
strdate = fmt.format(theServerGeneratedMessageEvent.getServerDate());
}else{
strdate = theServerGeneratedMessageEvent.getServerDate().toString();
}
setDateTime(strdate,widget);
WorkFlowSessionFactory.putValue(WorkFlowSesisonKey.SERVER_DATE_TIME,theServerGeneratedMessageEvent.getServerDate());
}
}
});
}
public static void setDateTime(String dateTime,Label label) {
if(label != null){
label.setText(dateTime);
}
}
*NTTimerEvent *
*
*
public class NTTimerEvent implements Event
{
/**
*
*/
private static final long serialVersionUID = 1L;
public static final Domain SERVER_MESSAGE_DOMAIN =
DomainFactory.getDomain("server_message_domain");
private Date serverDate;
private NTTimerEvent() {}
public NTTimerEvent(Date serverDate) {
this.serverDate = serverDate;
}
public Date getServerDate() {
return serverDate;
}
public void setServerDate(Date serverDate) {
this.serverDate = serverDate;
}
}
*Handler Code:*
public class UtilityCallerActionHandler extends
RemoteEventServiceServlet implements
ActionHandler<UtilityCaller, UtilityCallerResult> {
private static Timer myEventGeneratorTimer;
@Inject
public UtilityCallerActionHandler() {
}
@Override
public UtilityCallerResult execute(UtilityCaller action,
ExecutionContext context) throws ActionException {
try{
if(myEventGeneratorTimer == null) {
myEventGeneratorTimer = new Timer(true);
myEventGeneratorTimer.schedule(new ServerTimerTask(), 0,
10000);
}
return new UtilityCallerResult();
}catch (Exception e) {
CommonUtil.printStackTrace(e);
long exceptionBeanId = 0l;
if (e instanceof NTException) {
exceptionBeanId = ((NTException)e).getExceptionBeanId();
}
throw new NTActionException(NTException.getStackTrace(e),e.getCause(),
exceptionBeanId);
}
}
@Override
public void undo(UtilityCaller action, UtilityCallerResult result,
ExecutionContext context) throws ActionException {
}
@Override
public Class<UtilityCaller> getActionType() {
return UtilityCaller.class;
}
private class ServerTimerTask extends TimerTask
{
public void run() {
* final Date theEventMessage = new Date();*
* //create the event*
* Event theEvent = new NTTimerEvent(theEventMessage);*
* //add the event, so clients can receive it*
* addEvent(NTTimerEvent.SERVER_MESSAGE_DOMAIN, theEvent);*
}
}
}
--
You received this message because you are subscribed to the Google
Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected].
To post to this group, send email to [email protected].
Visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "Google
Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.