View Full Version : Problem with syncronism

6 Oct 2011, 10:47 AM
I'm having problems with synchronism in my aplication. Only one window can be exist, if any user try to access the same page in other window the system should close this window, restore the first window and show a message like: "Duplicated Instance of ... "
To do this I used Javascript Native, however, it somes like happening some kind of synchronism problem.
Sometimes works, sometimes not, I tried to use timers, but doesn't help very much, it is very unstable, like this:

Timer t = new Timer() {
public void run() {
if(GXT.isIE) {
} else {

final MessageBox box;
box = MessageBox.alert(
"Duplicated Instance... ",
new Listener<MessageBoxEvent>() {
public void handleEvent(final MessageBoxEvent be) {

Timer timer = new Timer() {
public void run() {
return ;

* Used to focus on the principal window
* Works only with IE
public static native void focusWindow() /*-{

* Resize the principal window
public static native void resizeWindow() /*-{
if (document.all) {
else if (document.layers || document.getElementById) {
if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth){
top.window.outerHeight = screen.availHeight;
top.window.outerWidth = screen.availWidth;

Does anybody know how can I solve this problem? Preferentially using GWT ?

Colin Alworth
8 Oct 2011, 3:40 PM
I'm having a difficult time understanding your code - it appears that you create a message box, but never display it, and you try to focus the window as well as resize it to not allow anything else to be done. These seem to make sense, but browsers are not designed to be able to take over the computer and prevent other apps from being run.

If you are trying to make sure a single session has only one running window at once, it could make sense to track this on the server, using whatever session is created when logging in. Another idea would be to assign each running app instance an timestamp from when it started, and set a single cookie - perhaps again use your timer to check that cookie, and if it doesnt match the currently running app's timestamp, there is a newer window, so block the user from using the current one.

The browser offers very little in this department, but your own application might be able to gain more control. For example, if you run IE twice, and log in twice, it will have two different sessions, and there will be no way to have your windows talking back and forth (in contrast Chrome and Firefox have their different tabs/windows share the same session/cookies). If your app launches in a new window from clicking a link, it could be possible to disable that link after it has been clicked once, and close the new page if the starting page is closed.

Taking over the screen entirely comes with the risk of something going wrong and your app no longer functioning, and also not allowing the user to do anything to fix it - be very sure that this is what you want to do before implementing this.

18 Nov 2011, 3:39 PM
I think you make some really good points here, and I have found your criticisms very helpful. It seems that I have many of the same misconceptions, and it is great that you have shined some light on that for me. All of this will help me out a great deal as I move forward on the payroll software (http://www.paycor.com/) development project that I'm currently working on. Thanks a lot for your help.