开发者

Difference between static variable in ActionScript and in Java EE

Please verify my understanding. When a static variable i开发者_运维问答s defined in a Java EE application, the variable is visible and can be altered by any other user. But in case of actionscript, the static variable's scope is the application running in browser's window.

In that case, is it possible to define a variable in actionscript to behave like the static variable in Java EE, beacause actionscript is client side and Java EE is server side ?


I guess that you need so called 'singleton' object - one object which is accessed by your whole system.

Even 'static' from Java won't help you here too much: there can be more than one copy of a static variable in JavaEE, for example when you use clustering, each machine in the cluster will run its own copy of the application, so will have its own copy of the 'static' variable. If you have (let's say) 10 clients (in Flash or Flex), and 10 clustered servers, each client may get its own server, so each client may get its own static variable on the server.

What's more, when the server is restarted, but the client is still alive, all your static variables are lost.

The only way to make the true, system-level singleton is to use a more complex solution, like:

  • save the 'singleton' data to some file on the server side, so all nodes in the cluster and all clients can access this file;
  • save the 'singleton' data to the database;
  • use application-scoped Enterprise Java Beans;
  • use Terracotta, which can turn 'static' variables into really static, persistent ones automatically with no changes in your code.


Your understanding of static is correct.

But this leed to the problem, that you want to share values between several Clients. But there is no simple solution. What you need is a Server, which store the value and the clients have to ask the server for this value and ask the server to update the value.


You can always pass the variable to browser via Javascript or to server via socket/urlloader/javascript.

Though to be more precise, static variable in AS3 has scope as you declare it - public, protected, internal, private - and is attached to specific class definition.


You can share values via P2P mesh network with the recently added Real Time Media Flow Protocol in FP10.1. Otherwise you can use a remote shared object to share values between different client machines (but requires a server side remoting solutions like FMS, WebOrb, FluorineFX, AMFPHP, etc).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜