Global Application variable
How do I set a global application variable in a Swing application?
Namely
MDI display opens a new window
new window sets a variable
close the new window and return to the MDI window
MDI window needs to use the variable.
Note: the new window is is its own class object.
What are you talking about?
Static variables are "global".
In some class (it does not really matter which) define
a static variable. O.K. now you have a "global"
variable.
Some people may say that this is "bad" programming
practice, but it is what you asked for.public static variables of public classes are 'global' in the sense you can refer to them if anywhere in an application. Public classes are also 'global' in this sense.
However, we don't call them global variables, they are class variables. A global variable is generally defined to be one that is associated with the running application. It has no context other than that. It can be used anywhere at any time without any qualifications. In other words, the are terrible.
I had to maintain an application that had 50 or so global variables. Some of these variables represented the exact same piece of information so it was cruicial during modifications to make sure that they were kept in sync. Don't use this type of design.
Similar Messages
-
Dealing with a turn based application with using a global static variable
Hi there. I read some articles about JavaFX concurrency,so as a newbie i have to practice on it. Now i'm trying to implement a turn based application that can be played among 3-6 players. Moreover, i use a scene imported from a .fxml file and i have to update it correctly depends on some calculations of each thread (in other word players ). My main issue is, i don't wanna use a while loop which checks the state of game like;
while( GameState != State.GAME_OVER ){
currentPlayer = GameBoard.getNextPlayer();
// do some actions,calculations etc.
So, i want to use worker threads instead of this while loop. I guess using Service class for iterating and assigning the next player will be suitable instead of using the while loop and Tasks for doing each player's calculation,or waiting for some responses from Human players on UI based,however, i'm struggling with two problems.
There should a global static variable ( like GameState which is an Enumarator ) determines the state of the game,so it should be updated and should be checked by each turn. Is there any way to do this ?
How can i get rid off this while loop ?
I will appreciate for every answer. Thanks anyway.It shouldn't make too much difference. The basic idea is that you have a model class representing your game state (the Game class in jsmith's example). When a player makes a move, you update the state of the game. Since this will result in changes to the UI, this update should be performed on the FX Application Thread.
If the player making the move is a human player, the move will likely be made by a user action (button press or mouse click, etc); this will be handled on the FX Application thread anyway.
When the state of the game changes so it is the turn of an "artificial" player to make a move, have the object representing the artificial player calculate its next move, and then update the game state. Since this is a response to the game state changing (it's now the turn of the artificial player), this will also be on the FX Application Thread.
The only (slight) complexity comes if the calculation of the move for the artificial player takes a long time. You don't want to perform this long running calculation on the FX Application Thread. The cleanest way to manage this is to launch a Task which calculates the desired move, and then updates the game state when the move is ready. So, something like this:
GameState game = ... ;
// UI is bound to the game state.
ExecutorService executorService = ... ;
final Player currentPlayer = game.getCurrentPlayer() ;
final Task<Move> calculateMoveTask = new Task<Move>() {
@Override
public Move call() {
Move move = // compute next move...
return move ;
calculateMoveTask.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
@Override
public void handle(WorkerStateEvent event) {
gameState.makeMove(currentPlayer, calculateMoveTask.getValue());
executorService.submit(calculateMoveTask);
If you're doing more threading than that, you're probably doing it wrong... . There should also be no need for anything to be held as a "global" static variable (the idea above is the only structural modification you need to the example posted by jsmith). -
Application Variables in application.cfm and asp
If anyone could provide some insight into using application
variables declared in application.cfm, but retrieved in asp code,
it would be appreciated.
GOAL: Retrieve values into an asp page from application
variables in application.cfm.
PROCESS: Defined the variables in application.cfm. On an asp
page, defined the application variable in Window -> Bindings.
The application variables defined in the source code show up.
Attempt to retrieve the application variable in the asp page by
using the command: var_destination = Application("var_name")
It seems like whatever I try, the variable is empty. After
looking around on the web, I also saw that the equivalent to
application.cfm in asp is global.asa. I also tried setting up this
file, along with the variables, did the binding, and used the same
commands, and also was not able to retrieve any application
variables.
What am I missing?What am I missing?
That ColdFusion and ASP.NET are different applications and do
not share
the same memory addresses So they are going to each have
their one
"application" variables.
Blue Dragon has implemented CFML as an ASP.NET language so
that one
could write ColdFusion that runs on the ASP.NET framework and
would then
use the same memory locations with their server.
Otherwise you are going to have to write your own sharing
tool. Some
code that can read the desired variables from one code base
and pass it
to the other code base through forms, web services or some
other manner. -
Best way to manage global application data
Hello,
I'm looking for the best way to manage my global application data. I have a program containing about 70 application settings which are loaded from an ini file and organised as clusters and loose variables. I want to be able to use these settings across multiple vi's. The application settings can be modified during execution. Some vi's can change settings and these changes need to be visible accros all vi's.
What is the best way to manage this. Ideally, I would have one cluster or class containing all the application settings but since the sub vi's run independend, I can't wire them through.
From what I've read so far, global variables ain't really well suited for this due to race conditions. The FGV might be a solution but it is not clear to me how to implement this for many variables. (One FGV or multiple FGV's, etc... Does anyone have a good example of this?)
Are there any other good solutions? Any advice is welcome!
Best regards,
WouterYou can also create a singleton LVOOP object (maybe a few if you want to logically organize your settings). When you initialize the system you create the object and it uses a DVR internally to store your data. Since this is a singleton object you do not need to wire it through your code. Your subVIs simply call the appropriate methods and it will interact with the class data. A FGV is basically the same thing except that you only have a single VI so you are more limited with your inputs and outputs. A singleton object let's you refine the connector pains based on the methods and what they are doing.
Mark Yedinak
"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot -
Are application variables 'user specific'?
hi - i've got a feeling i may have done something stupid.
we have several domains all pointing to one application.
in application we look at the cgi.http_host to work out which
site the domain the user is expecting and then serve up customised
content accordingly.
only this is i've set put the customised content in
application scoped vars - is that a bad move?
eg. in application.cfm i have:
<cfif cgi.http_host eq 'www.redredred.com' >
<cfset application.message= "welcome - we love the colour
red" >
<cfelseif cgi.http_host eq 'www.blueblueblue.com' >
<cfset application.message= "welcome - to our site where
we love blue" >
<cfelse>
<cfset application.message= "welcome to our site (we love
all colours)" >
</cfif>
then in the index.cfm:
<cfoutput>#application.message#</cfouput>
is there a chance that by doing this someone who has visited
www.redredred.com will get a message about blue?happysailingdude wrote:
>
> is there a chance that by doing this someone who has
visited www.redredred.com
> will get a message about blue?
>
Not only a chance, but there is something wrong if the person
does not
get this message, once the next user has set the variable to
blue.
Application variables are global to the application and will
be shared
by all users of that application. That is the designed and
desired
purpose of application variables.
In ColdFusion an application is defined by any template that
shares the
same 'name' as defined in either the name parameter of a
<cfapplication...> tag or the this.name property of an
Application.cfc file.
If all these web sites are using the same string for the
application
name then they share the same application scope and they will
all have
the same value for application.message. And this value will
be the
value set by the last visitor to any of the sites.
<cflock...> is not relevant to this issue. It will
prevent the variable
from being set at the exact same moment by multiple users on
multiple
sites, but it will not stop the value from changing
sequentially as
first one, then another user visits any of these sites and
changing the
value.
The solution to your problem is to set different application
scopes by
dynamically setting the application name. Thus each website
will be
separate and distinct applications with their own application
scope
variables and your system should behave the way desired. -
How to Obtain the Value of a ***Global*** Application Item from JS
If we declare an Application Item, i.e. NOT a page level item, how do we obtain the value of that Item in a JavaScript Dynamic Action on a page?
For example, we declare a "global variable" as an Application Item named DEFAULT_AJAX_SEPERATOR and set its value with an Application Computation "On New Instance" At some later point, on a page in the application, we'd like to obtain the value of DEFAULT_AJAX_SEPERATOR via JavaScript.
The page* level item syntax...
$v( 'DEFAULT_AJAX_SEPERATOR' );...does not work. I do understand why this is as $v can only access items on the page. However, APEX is clearly able to obtain such global values since, for example, they are available in PL/SQL blocks. Also, I know it's on the session object because I can see it when viewing the session.
So...what's the secret sauce for obtaining that value?
Thanks,
-JoeHello Joe,
>> on a page in the application, we'd like to obtain the value of DEFAULT_AJAX_SEPERATOR via JavaScript … So...what's the secret sauce for obtaining that value?
The secret is to define a global JavaScript variable and set it with the value of the item, using Substitution String notation. For example:
var default_ajax_separator = &DEFAULT_AJAX_SEPERATOR.This code should be placed in the Function and Global Variable Declaration field, under the JavaScript section of the Edit Page. As we are talking about a global JavaScript variable, it will be available to every other JavaScript code on the page.
Regards,
Arie.
♦ Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.
♦ Author of Oracle Application Express 3.2 – The Essentials and More -
How to assign itemrender variables in global public variable of my applicaton.
Hi Friends,
How to assign internal item render values in global public variable. can u see below example.
List have one itemrender,within the itemrender i am using data grid .The dataGrid have itemrender.now i tried the data grid itemrender assign values to public variable of my application,but the Error came... How can u slove this Problem Any One can Help to me.
Example:
public var myData:arrayCollection;
<mx:List variableRowHeight="true" dataChange="validateNow()" width="900" id="Lst_userlist" verticalScrollPolicy="off" horizontalScrollPolicy="off"
buttonMode="true">
<mx:itemRenderer>
<fx:Component>
<mx:VBox paddingTop="-5" horizontalScrollPolicy="off" verticalScrollPolicy="off" >
<fx:Script>
<![CDATA[
override public function set data(value:Object):void
]]>
</fx:Script>
<mx:VBox id="vbox_grid" horizontalScrollPolicy="off" verticalScrollPolicy="off" width="890" paddingLeft="10" paddingTop="5"
backgroundColor="#317152" color="#FFFFFF">
<mx:DataGrid visible="false" includeInLayout="false" height="100%" id="membershipGrid" alternatingItemColors="[#DCDCDC,#F8F8FF]"
paddingLeft="5" horizontalScrollPolicy="off" color="black"
horizontalGridLines="false" verticalScrollPolicy="auto" verticalGridLines="false" rowHeight="25"
borderSkin="{null}" showHeaders="true" borderVisible="false" dataProvider="{data.dataCollection}" width="900" >
<mx:columns>
<mx:DataGridColumn width="180" headerText="Name" minWidth="150" sortable="true" wordWrap="true" >
<mx:itemRenderer>
<fx:Component>
<mx:HBox horizontalScrollPolicy="off" >
<fx:Script>
<![CDATA[
override public function set data(value:Object):void
function Click_Name():void
outerDocument.myData=data; // Here Error came
]]>
</fx:Script>
<mx:Image id="fileimg" buttonMode="true" toolTip="This is the User's Home Organization"/>
<s:Label id="lbl_Gridcloumn_name" width="200" buttonMode="true" textDecoration="underline" click="Click_Name()" />
</mx:HBox>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</cloumn>
</datagrid>
Error:
Access of possibly undefined property myData through a reference with static type com.istmanagement.views:ProgramAcessRights_ComponentInnerClass3.
Thanks,
Magesh R.Hi Flex harUI ,
Thanks man....because of i was stugle in last one week.... once again Thanks....... -
Accessing Tomcat Global Environment Variables
Hello,
I have tried to access Tomcat 5.0 (xx) Global Environment variables.
I have the Integer simpleValue defined in the Tomcat Administrators panel under "Environment Entries"
Here's my code:
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:comp/env");
Integer i = (Integer)e.get("simpleValue");
I have also tried and infiinite variation of this with no success (Accessing the Initialcontext directly)
The Tomcat docs at: http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-resources-howto.html
says:
"<Environment> - Configure names and values for scalar environment entries that will be exposed to the web application through the JNDI InitialContext (equivalent to the inclusion of an <env-entry> element in the web application deployment "
PLEASE HELP !!!
Geir OveThis is a Tomcat bug. See http://nagoya.apache.org/bugzilla/show_bug.cgi?id=14228.
-
Problem with application-variables - CFLOCK?
Hi,
i have a problem with my application. It is a multi-user
application with 100 parallel-users and CFMX 7.
The problem wich occures is with application variables. These
are mainly structs wich get filled onApplicationStart(). The
problem is, that the variables suddenly disappear, they are empty.
I have read about CFLock and found out, that it is necesseary
to use cflock. And i found out, that onApplicationStart does
correct locking automatically. That is where i do not understand
the problem. The variables get intialized correctly and in further
they only get read-access. Why can they be corrupted?
My other question about that is, wheather i need cflock for
all Read-Access to Application and Session-Variables, even if there
happens no writing to the variables?
Best Regards,
Andreas> ?The element of position 2, of dimension 2, of an array
object used as part of
> an expression, cannot be found.?
> The array is in this case the struct.
Well, OK, that could be a problem. Arrays are not structs:
they are two
different things, are not interchangeable, and have
completely different
sets of functions to utilise them. You cannot treat a struct
as an array.
If CF is claiming your "struct" is an array, then it actually
*is* an
array, not a struct.
What's the line of code which is generating that error?
I suppose one could get this error if you have an array of
structs thus:
myArray
.key1
myArray.key2
(etc)
and you're trying to reference it with a numeric key rather
than by key
name, eg:
myArray
[n]
When n is an integer value, rather than a string (which
corresponds to the
name of the key).
> > Have you trapped the error, done a <cfdump>
of the application scope and
> > checked to see if it's the whole lot going awry, or
just some values?
> I have not used cfdump for it, because the server had to
be immediately
> restarted for our customers. But i think, that it is
not completely empty,
> because the index runs to pos2 of dimenstion2.
So does this not happen in your dev / testing environment?
> Will
> onApplicationStart() be called before? Or only if
onRequestStart() returns true?
I would ***-u-me that the application one would be called
before the
request one. It's pretty easy for you to test this though, I
should think?
(Sorry: for reasons beyond the scope of this conversation,
we're still
forced to use Application.cfm in our software, so I've only a
passing
knowledge of how Application.cfc works).
> Here is the code from onRequestStart()
> <cffunction name="onRequestStart"
returntype="boolean">
> <cfargument name="Requestedpage" required="yes" />
> <cfscript>
> var lFile = "/cargorent/Login.cfm";
> var iPosn = ListFindNoCase( lFile,
Arguments.Requestedpage );
> if( iPosn gt 0 )
> return true;
>
> if( NOT IsDefined( "session.user.Loginname" ) or
session.user.Loginname eq
> "" )
> {
> WriteOutput( "<p><p> The current user is no
longer valid, please log in
> again.</p></p>" & chr(10) & chr(13)
> WriteOutput( "<script
language=""javascript"">parent.location = ""
http://"
> & CGI.HTTP_HOST &
"/Login/Login.cfm"";</script>" );
> return false;
> }
>
> return true;
> </cfscript>
> </cffunction>
One thing I will say here is that I really think you should
be separating
your processing from your display. A function should do
processing. it
should pass that processing back to a CFM template which
should handle
whatever needs to be displayed on the browser. Although
that's nowt to do
with your current issue.
Adam -
How to Create and Use Application Variables in Java
I Have this need to have a common variable (Counter) for all the users(Sessions) accessing my Site witch is in JSP.
I think An Application Variable is the solution for my problem...
But I don't know how to use this. Even though I search the web for any tutorials or Examples could not fing any.
Could any one Please tell me or direct me to a site which has good information about this
Thanks In Advance!!!
Badsy.// get the application object
public class myServlet extends HttpServlet
public void doGet(HttpServletRequest req,
HttpServletResponse res)
ServletContext application = getServletContext();
} -
Performance: Database Update vs. Application variable
I am new to ColdFusion, so sorry if this has been covered before. I searched and couldn't find anything similar.
I am building an online Texas Hold'em poker application using ColdFusion and Flex. There are quite a few things that need to be stored on the server side that will be updated quite often and these objects will need to be accessed by multiple users. For example, think of something like the current pot between players on a table, or the current hand state (who's turn it is to check/bet/raise), or the current players in the hand. All of these things will be updated quite a few times per hand, and if you add to that that each of these will be different per table, it adds up quick.
Would it be better to store these things in the database or store them in an application variable? Or is there a better way that I am not thinking of? Is there any sort of metric to follow for these kinds of things?I don't think you'll find a documented general number of application variables you can have on a single server. But I think you could get away with 400 variables without any trouble.
Where you might run into trouble, though, is when you have multiple concurrent requests trying to read and change these values. You'll have to ensure that you single-thread write access to these variables using CFLOCK.
Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
http://training.figleaf.com/
Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on
GSA Schedule, and provides the highest caliber vendor-authorized
instruction at our training centers, online, or onsite. -
Global Application Parameters for EJB
Hello all, I did a search for this on these forums and there are there a TON of threads of developers wanting to implement the classic Singleton pattern so that all EJB's of an application can access "Global Application Parameters". Most of these I've been reading achieve this by workarounds that breakdown at the clustering level, since Singletons won't span multiple JVMs.
Suppose you deploy an EAR that only has EJB jars, so you don't have access to all the convenience of the web tier (context parameters, context Initialization, etc.), so there is no way for your EJB's to detect/intercept an "Application Startup" event and load any necessary values into a Global Application parameter repository.
This seems such a widely demanded functionality that I wonder if there now a "best practice" way to achieve equivalent of the Singleton pattern in the EJB world that works nicely in a clustered environment?I have the same problem
Thanks -
Sometimes application variables don't reset
In our application.cfm, many queries are run and set to arrays that are application scope. They are for code tables. To keep all this from happenning each time a template runs, there is a server scope variable that is set to true from another program and in application.cfm, there is something like <cfif the server variable is true> run queries,assign arrays,set server variable to false </cfif>.
When a new code is added to a code table, we set the server variable to true and the next template that runs resets all the application variables and the new code is in one of them.
Sometimes this doesn't work. Only some of the arrays get reset and the others are empty. The arrays are there but have no elements.
Repeating the process 2 to 4 times seems to make it work.
What can cause it not to work the first time ?The problem happens even in a test area where I'm the only one using it.
Why does the reset program sometimes have to be run more than once ?
This is the reset program
server.x=0
This is what the application.cfm is like
<cfapplication name="thename">
<cfset ds="dsname">
<cfparam name=server.x type="boolean" default="0">
<cfif server.x eq 0>
<cfset server.x=1>
<cfset application.codes=arraynew(2)>
<cfquery name="qcodes" datasource="#ds#">
select codes, desc from tblcodes order by codes
</cfquery>
<cfloop query="qcodes">
<cfset application.codes[currentrow][1]=qcodes.code[currentrow]>
<cfset application.codes[currentrow][2]=qcodes.desc[currentrow]>
<cfset application.codes[currentrow][3]=qcodes.place[currentrow]>
<cfset application.codes[currentrow][4]=qcodes.date_eff[currentrow]>
<cfset application.codes[currentrow][5]=qcodes.date_del[currentrow]>
</cfloop>
does this for well over 50 more tables
</cfif> -
Hi
Give me idea on Global Container variable in Graphical mapping.
Thanx in AdvanceHi
Ref this
/people/sravya.talanki2/blog/2005/12/21/use-this-crazy-piece-for-any-rfc-mapping-lookups
http://help.sap.com/saphelp_nw04/helpdata/en/95/bb623c6369f454e10000000a114084/content.htm
Design and Configuration [original link is broken]
Thanks
Sridhar -
Global Application Contexts - Where to set Client Identifier?
Hi,
I am trying to use global application contexts as part of an implementation of fine grain access control.
This is within an eBusiness Suite environment, specifically CRM, so is a multi-tiered environment.
Users access both Forms based screens and OA framework screens.
I believe I need to use global application contexts as users may have multiple database sessions.
Also, all users will login using the same database login account.
Provided I can set a unique identifier for a user that persists throughout all their sessions I can make use of the username and client_id parameters of set_context, below:-
DBMS_SESSION.set_context (namespace => 'XXUOM_CONTEXTS',
attribute => 'EXEMPT_FROM_VPD_POLICIES',
VALUE => l_exempt,
username => USER,
client_id => pi_user_id);
The difficulty I am having is finding a suitable place to set the client identifier.
I am not sure if the value is being cleared by some other code or if the value isn't being set in all sessions.
I am using:-
DBMS_SESSION.set_identifier (pi_user_id)
That I call from after insert triggers on either tables icx_sessions or fnd_logins.
However, the client identifier is always null when I query it from within the application, via:-
SELECT SYS_CONTEXT ('USERENV', 'CLIENT_IDENTIFIER') from dual
If I set the value via a personalisation rule within a Form, then the value remains.
I would greatly appreciate it if someone can advise me on where I am going wrong.
AndyIt's a different patch.
The patch support have given me is 9275708, FND_GLOBAL.ORG_NAME RETURNS ENGLISH, EVEN WHEN SESSION LANGUAGE IS NOT.
This patch has been superceded by 12875860, HR SECURITY PROFILE IS NOT SET CORRECTLY.
So we have applied patch 12875860.
I've tried to find out from support what happened to the original patch and why it was removed/deleted rather than superceded.
I have not found it possible to find out what each of these patches does. There's very little documentation on them.
I have raised an SR.
The details are 3-4943519401: How to add DBMS_SESSION.SET_IDENTIFIER() to FND_GLOBAL.INITIALIZE.
The results of:
select fnd_profile.value('FND_CONNECTION_TAGGING') from dual
gives nothing on our Release 11 environment.
select * from fnd_profile_options where profile_option_name = 'FND_CONNECTION_TAGGING';
gives nothing.
On Release 12, the results are:
select fnd_profile.value('FND_CONNECTION_TAGGING') from dual;
ENABLED
select * from fnd_profile_options where profile_option_name = 'FND_CONNECTION_TAGGING';
returns a record.
Many thanks for continuing to look into this for me.
Andy
Maybe you are looking for
-
Unable to create a new folder in document library of SharePoint 2010
Hi There, Need some help regarding an issue which is occurring after migration from SP 2007 to 2010. We have recently migrated a site to SP 2010, after migration whenever i tried to create a new folder in a document library it gives me an error messa
-
How to combine .wmv files into one file???
Hello Apple World, Can someone tell me a software that will allow me to combine ".wmv" files into one? I have several files that I need to combine then add music to. VERY simple with several software packages frow Windows pc's, but I'm struggling wit
-
Why do my audio files import as loops?
Hi peeps. Wondering if someone could help clear this one up. Whenever i import/drag in audio files they import as loops with a little up/down arrow on the top left of the region. This makes it very tricky to do edits as i frequently click on the arro
-
Same old Bondi blue FBT story, but with a twist?
Hi. I've been all over the internet trying to understand the FBT workarounds for an old Rev A Imac and I apologize in advance if this is a redundant question. I must admit I'm now a little confused. I think the problem with the computer is a bad FBT.
-
Comparison Between Oracle eBS and JD Edwards
Hi All, Is there any site / document / any kind of referference / help on comparison between Oracle-eBS and JD Edwards mainly for Finance and SCM module please ? Need this urgently so any help is appreciated. Thanks & Regards, Subhra Saha