Handling static objects
Hi,
I would like to know how are static objects handled in java
Questions:
1) What is the lifetime of a static object.
2) can a static object called through any class on the jvm be reclaimed
to phrase the above question better, If a class has a static object can i free the memory at anytime.
3) Can i have links to handling of objects by the jvm if any.
Any pointers are highly appreciated.
Thanks and regards,
myraid_77
Static variables are associated with a class, not an instance.
So, as long as the class is loaded, the static variable will remain.
You would have to create your own classloader, and load a class ( containing the static variable ), through the classloader..... then later on null all references to the classloader, to unload the class from memory.
The easiest way to reclaim memory from a static variable is to set it to null.
regards,
Owen
Similar Messages
-
HI Guys...
I am working on a RFC to HTTP scenario:
It is a standard SAP interface ....so we created only ID objects..obviously the BPM delivered by must be correct.
in sxmb_moni_bpe it is throwing th following error texts:
Runtime handle of object type could not be created
Error executing service for node
Exception CX_MERGE_SPLIT occured
component mapping has returned an error
unmodeled exception when executing service for node
No payload found
object FLOWITEM method EXECUTE cannot be executed
I tested the mapping payload from sxmb_moni in IR and it is working fine.
Receiver is an HTTP so could not able to find exactly whats happening as no thrid party tools can be installed....struck up here.
Any iputs will be of help in this area.
Thanx in adavance.
Kiranany inputs around this plz??
-
Handling 3d objects using JavaScript for Acrobat 3D Annotations API
I am trying to learn how to handle 3d objects with this manual: http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/js_3d_api_reference.pdf
When I execute some code, for example,
myTimeHandler= new TimeEventHandler();
myTimeHandler.onEvent= function( event )
console.print( "Current simulation time is:" + event.time );
console.print( " second(s)" );
runtime.addEventHandler( myTimeHandler );
I get an error like this:
TimeEventHandler is not defined
Why?
P.S. I have 3d object in the document, and can get it with function getAnnots3D.You have to run the code in the context of the 3D annotation (by attaching the script to the annotation's properties panel, or by right-clicking the active 3D scene and choosing "run a javascript". You cannot run it in the console.
-
Cluster and static object.
I have application worked in cluster. Is some possibility to propagate change in static object to all application in cluster.
You can use application context (javax.naming.InitialContext) and bind (set), rebind (set new value), lookup (get) and unbind (remove) variables (must be serializable).
You must corect configure RMI replication.
Changes ist propagated acros all nodes in cluster. (but unbind don't work correct - it work only locale (bug?)) -
Client-Side Caching of Static Objects
Hi,
We just installed SPS12 for NWs. I learned of this new client-side caching of static objects while reading through the release notes, and I went in to our portal to check it out. I went to the location where the <a href="http://help.sap.com/saphelp_nw04s/helpdata/en/45/7c6336b6e5694ee10000000a155369/content.htm">release notes</a> (and an <a href="https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/6622">article in the blog</a>) specified, System Administration > System Configuration > Knowledge Management > Content Management > Global Services.
Problem is that I do not see Client Cache Service and Client Cache Patterns. I enabled "Show Advanced Options," but I do not see those two configuration items.
Does anyone know why I am not seeing those two configuration items and how I can get to those?
Thank you.Hi,
We are using SPS 12.
KMC-CM 7.00 SP12 (1000.7.00.12.0.20070509052145)
KMC-BC 7.00 SP12 (1000.7.00.12.0.20070509052008)
CAF-KM 7.00 SP12 (1000.7.00.12.0.20070510091043)
KMC-COLL 7.00 SP12 (1000.7.00.12.0.20070509052223)
KM-KW_JIKS 7.00 SP12 (1000.7.00.12.0.20070507080500) -
Layer static objects/text on top of interactive elements
is it possible to layer static objects/text on top of interactive elements (including scrollable slideshows or MSO) in INDD CC for DPS/Content Viewer? The static objects (on their own layer) disappear when viewed on tablet in Content Viewer
Thank you so much!
Taylor Guilmette | Senior Graphic Designer
CBRE/Grossman Retail Advisors
33 Arch Street, 28th Floor | Boston, MA 02110
T +1 617 912 7052 | F +1 617 912 6867
[email protected]<mailto:[email protected]> | www.cbre.com/taylor.guilmette<http://www.cbre.com/taylor.guilmette>
Follow CBRE/Grossman Retail Advisors: @CBREGRA<https://twitter.com/CBREGRA> -
How to handle lock object in BDC call transcation method?
Hi,
how to handle lock object in BDC call transcation method?
Thanks In advances.If you are updating Z-fields then you need to create a lock entry, before you use call transaction.
After creating lock object, please use FM Enqueue_<lockname> before CALL transaction and FM Dequeue_<lockname> after you have commited your data.
Thanks,
Kartavya -
Third-party C++ Driver : Static object
Hello,
I'm writting a C++ driver for Labview RT.
I'm using Visual C++ to compile and link this driver.
I have some initialisation problem on the target.
It seems that static object are not created correctly. All members are not created correctly and it crashes as soon as I use these objects.
Could someone confirm this problem ?
Is there someone develop a C++ driver (based on VISA) for Labview RT ? Thanks for your responses !
David ChuetDavid:
For starters, note that NI does not officially support MSVC-built DLLs on LabVIEW RT. I believe we only officially support DLLs built with LabVIEW or CVI. However, in most cases MSVC-built DLLs will work fine.
As to your specific question, you are correct. C++ static objects don't get initialized. Realize that the LabVIEW RT OS (Phar Lap ETS) is Win32-like. In other words, it is not 100% compatible with Win32 and MSVC, but it is extremely compatible with a large subset of the two. This is probably the biggest difference I can think of.
My suggestion is to have static pointers to objects, then initialize them in your DLLmain. That does work and that's how we do it in NI-VISA.
Dan Mondrik
National Instruments -
If an object were static, would its non-static members act like static? What kind of problems would happen if two threads try to use this object to call one of its non-static functions? Would any member of this object (either static or non-static) be part of a critical section?
jverd wrote:
wpafbuser1 wrote:
There's no such thing as a static object (since there's no instance).No, there's no such thing as a static object because the property of being static or not is not applicable to objects. Saying there's no instance is wrong, since, if there's an object, there's obviously an instance--the object.I wrote too fast, I meant there's no instantiation. Obviously there's an object/instance. But my thinking was flawed there anyway. :)
A class is considered static when it's fields and methods are static.No. A class is static when it's a nested class and it's declared static. A class is often incorrectly called static simply by virtue of it having only static members. Regardless of whether the class is static, all instances of that class are neither satic nor non-static.The term static, incorrectly used or not, I was referring too top-level classes not inner classes.
I guess what I'm saying is that if you include non-static methods or fields in your class, it's no longer a static class Wrong.
class Outer {
static class Nested {
int x;
void foo() {}
}Nested has a non-static member variable and a non-static method, but it's still a static class, because it's declared static.Again, we're talking about 2 different things now. -
How to persistent static object
JDO always assigns a StateManager to a PersistenceCapable object when
creating instance. If an object is static, it'll keep its StateManager for
ever after instantiation. So If I excute the following code repeadly, kodo
will complain that persistence manager has been closed.
1) Get PersistenceManager
2) Begin transaction
3) Get object from datastore. If not exist, create a new object. This
object is a static.
4) Commit transaction
5) pm.close
For the first time, kodo will assign a new StateManager to this static
object. But for the second time, exception, "persistence manager has been
closed", will arise when excuting some of object's methods. Because each
StateManager object owns a PersistenceManager object. If this pm is
closed, according StateManager object is also useless.
After enhancing, kodo will change some getter/setter methods to
according jdo getter/setter ones. These methods may invoke
startManager.isLoaded(), which invokes pm.isActive(). Unfortunately, pm
has been closed.
Any other tricky methods to persistent static object ?
Thanks !Dear Marc,
Thanks for your kind help. It's an effective advice to prevent
persistent object from being static.
However, what if the object to be persistent is an enumeration type
constant ? For example :
public class MyEnumType
private String name = null;
private int value = 0;
protected MyEnumType( String name, int value )
this.name = name;
this.value = value;
public static final TYPE_1 = new MyEnumType( "type 1", 1 );
public class EnumTypeUseClass
private MyEnumType type = null;
public void setType(..) {..}
public MyEnumType getType() {..}
public class TestClass
public void f()
PersistenceManager pm = null;
try
// Obtain pm
pm = ...;
pm.currentTransaction().begin();
EnumTypeUseClass use = new EnumTypeUseClass();
// Obtain myenumtype object from datastore
MyEnumType type = getJdoObject( pm, MyEnumType.class, "value ==" +
MyEnumType.TYPE_1.getValue() );
// Following line will cause "PersistenceManager has been closed"
exception
use.setType( type );
pm.makePersistent( use );
pm.currentTransaction().commit();
catch( .. )
finally
pm.close();
public static void main( String args[] )
for( int i = 0; i < 10; i ++ )
f();
Actually, exception is caused by MyEnumType.TYPE_1.getValue() because
this object's pm has been closed in the first loop time.
Now I solved this problem by not persistent MyEnumType objects, and
change type field in EnumTypeUseClass from MyEnumType to int.
But I still wonder how to persistent static objects.
Maybe your first advice is feasible, but I think it will make your
program tangly. Do you think so ? :)
Marc Prud'hommeaux wrote:
Liang-
You are correct that a persistent instance must be associated with a
PersistenceManager. You could always just leave the PersistenceManager
open (if using optimistic transaction, Kodo won't tie up database
resources in this case). Another option is to not have the singleston
instance be a static variable, but have it be obtained via a factory
method that takes a PersistenceManager argument.
If this doesn't help, perhaps you could help clarify the situation by
posting some code that shows that you would like to do?
In article <[email protected]>, Liang Zhilong wrote:
JDO always assigns a StateManager to a PersistenceCapable object when
creating instance. If an object is static, it'll keep its StateManager for
ever after instantiation. So If I excute the following code repeadly, kodo
will complain that persistence manager has been closed.
1) Get PersistenceManager
2) Begin transaction
3) Get object from datastore. If not exist, create a new object. This
object is a static.
4) Commit transaction
5) pm.close
For the first time, kodo will assign a new StateManager to this static
object. But for the second time, exception, "persistence manager has been
closed", will arise when excuting some of object's methods. Because each
StateManager object owns a PersistenceManager object. If this pm is
closed, according StateManager object is also useless.
After enhancing, kodo will change some getter/setter methods to
according jdo getter/setter ones. These methods may invoke
startManager.isLoaded(), which invokes pm.isActive(). Unfortunately, pm
has been closed.
Any other tricky methods to persistent static object ?
Thanks !
Marc Prud'hommeaux [email protected]
SolarMetric Inc. http://www.solarmetric.com -
Trouble understanding static objects
Hello,
I have trouble understanding static objects.
1)
class TestA
public static HashMap h = new HashMap();
So if I add to TestA.h from within a Servlet, this is not a good idea, right?
But if I just read from it, that is ok, right?
2)
class TestB
public static SimpleDateFormat df = new SimpleDateFormat();
What about TestB.df from within a Servlet? Is this ok?
example: TestB.df.format(new Date(1980, 1, 20));There is exactly one instance of a static member for every instance of a class. It is okay to use static members in a servlet if they are final, or will not change. If they may change, it is a bad idea. Every call to a servlet launches a new thread. When there are multiple calls, there are multiple threads. If each of these threads are trying to make changes to the static memeber, or use the static memeber while changes are being made, the servelt could give incorrect results.
I hope that helped..
Thanks
Cardwell -
How to make a handling unit object (packing) automatically generate from inbound
Hi guru,
I just have a question which I am sure sure and puzzle, and hope you can give me an accurate information.
Background:
We are using EDI communication so that vendor can send us advance shipping notification and will lead to inbound delivery creation automatically.
Question:
We would like the vendor, when deliver the shipment for us to be packed base on our instruction, and we want the handling unit object to be created automatically upon inbound delivery creation from the EDI. How to do this in SAP?
Thanks.
Danielif you are using message type DESADV / SHPCON then vendor needs to send the HU information in the E1EDL37(HU Header) / E1EDL44 (HU Item) segment and during Inbound delivery creation system will update the IBD with HU . Have a look on the below standard Link to get more detail
Delivery Interface - Shipping (LE-SHP) - SAP Library -
Synchronization on a static object
If I have a code like:
synchronized(_otherParsers)
_otherParsers = new Vector();
} knowing the _otherParsers is a static object in the class, the synchronization will block all access to the object or it will block the access to the sync. block?
OBS: So when one thread enters the synchronized block, accesses to that object by other threads are blocked until the original thread exits the synchronized block. [PENDING: verify previous statement, and figure out if synch'ed blocks block out all method calls on the object or just synch'ed ones] (quote from Java Tutorial, http://java.sun.com/docs/books/tutorial/together/bingo/synchronized.html)IIRC, when using synchronize(someObject) then
someObject is locked, meaning that the original object
isn't locked. So other methods will execute correctly.let's say the following:import java.util.Vector;
public class A {
public static Vector v = null;
public A() {
v = new Vector();
public static void main(String[] args)
B b = new B();
new Thread(b).start();
new A();
class B implements Runnable {
public void run() {
synchronized(A.v) {
A.v = new Vector();
A.v.add("test");
}As you can clearly see, the static vector, member of A class is initialized twice (once by the new A() in the main method of A class and once by A.v = new Vector() in the run() method of B class). Assuming the thread enters the synchronized block before the call to new A() in the main method, when that call ocures, is the A.v object locked? or not? -
Static Object Vs. Lots of referece passing...
I am implementing a discrete event simulator for which there is only ever one "executor" object and one "output manager" object used to advance time and deal with output to files. However many objects in the simulator need access to these objects and there "security" is not an issue. I was wondering if anyone knows if it is gives better performance to make these classes with static methods or whether I should pass a reference to them to nearly every other object. Also do you know why whatever one is beter?
Cheers,
MarkFor this project performance really is the issue
though. My concern is that if I pass a reference of
an object to lots of other objects (in the order of
100,000) that is simply a waste of time and memory
So let's get this straight. You can have 100,000 Objects, but you can't add one reference varialble to each.
if making the objects access methods static may
remove this I will happily accept this over
management and testability issues. What do you think making the method static will save you, exactly?
What I really want to know is for example...
is the above less effective than...No, generally , static methods are less effective than instance methods.
if StaticObjectType in the later example is the same
as the OtherObjectType in the first example., but
with a static method, given that only one instance of
OtherObjectType will ever exist. This makes no sense. There is no such thing as a 'static' Object. Static only applies to references and methods and nested classes.
My worry is that passing this object address around
and storing it as a field will be far less effective
than having just a static method, although I am not
sure this is true.There is a slight performance hit when calling an instance method over a static method. Declaring a method final may remove this. When I say slight, I mean really slight. Both methods are called in the basically the same manner.
As this is happening thousands of times a second in
this program and storage and speed are key really
just need to choose the most efficient
implementation.Again I don't understand how you can afford o have thousands of Objects but can't afford an extra reference on them. -
Static Object doesn't get collected
Hi,
I have a class JLog to log all the messages to a file. The JLog class is in a jx.war file which is deployed to the application server JBoss.
If the jx.war is deployed once, the messages printed to the file only show up once, which is fine.
But if the jx.war is deployed twice, the messages printed to the file show up twice.
If the jx.war is deployed three times, the messages show up three time and so forth.
My question is why the static object jLogger from the previous deployments doesn't get collected.
I think switching to Singleton implementation will solve this issue.
But are there any other ways to sovle it?
public class JLog {
private static int logLevel = getLogLevel();
private static long line = 0;
static Logger jLogger;
private static PatternLayout jLayout = null;
private static Appender jAppender = null;
public static void toLogger(String msg ) {
try {
if ( jLogger == null ) {
// System.out.println(" *** get a new logger *** ");
jLogger = Logger.getLogger(JLog.class.getName() );
jLogger.setAdditivity( false );
jLogger.setLevel( Level.ALL );
if ( jLayout == null ) {
// System.out.println(" * new patternLayout " );
String pattern = "%d{yyyy-MM-dd HH:mm:ss,SSS} - %m%n";
jLayout = new PatternLayout( pattern );
pattern = null;
if ( jAppender == null ) {
// System.out.println(" * new FileAppender " );
String filename = "jx.log";
String dataPattern = "'.'yyyy-MM-dd";
jAppender = new DailyRollingFileAppender( jLayout, filename, dataPattern );
filename = null;
jLogger.addAppender( jAppender );
jLogger.debug( msg );
} catch (Exception e) {
System.out.println("Exception! JLog.toLogger >>> " + e.getMessage() );
e.printStackTrace();
} // try
} // toLogger
}Each application in an application server is independant.
This means singletons, and static values appear once per application. i.e. each application has its own copy.
Maybe you are looking for
-
Best Practice Questions: Method signature for CRUD operations
Hi, I am reading a book about EJB3.0 which has been very helpful to me so far. However I now find myself in a dilemma which is not clearly covered in the book and I would really like to know how best to proceed. In the book it says that an Entity Man
-
How good is a Macbook Pro with dual video cards for gaming?
I've been a PC guy my whole life (aside from my iPhone which I love). My gf has been pushing me to try out a mac and considering how my PC laptops have a pretty good track record of dying on me or encountering some other problems after a year or two,
-
HT1657 Rental download failure
Cannot complete a rental download to my ipad2, started but not complete. Cannot delete and start again. Cannot restart in ITunes due to download started.
-
Hopefully a fix for app world error
i checked other forums and came across this help, hope it works for you as it worked for me :-) 1) Go to this link http://www.bbh-plus.net/downloads.php?do=cat&id=167 with ur phone – find what OS u use in ur phone 2) Download App World from that link
-
In Photoshop CS6 when I save a TIFF file it saves with the .sgi extension. When I save a png it saves it with the .raw extension. I haven't had this problem with previous versions of PS. I'm on a Mac with OSX 10.6.8. I also noticed that I have a plug