Caching Long Objects

Hi,
I would like to know why is Long objects are not cached internally and pooled in Java. Since Long objects are immutable there shouldn't be any problem in doing this right? Let me know am I missing anything here...Currently for one of my applications Iam planning to do this caching of Long objects myself. But the code for that looked pretty ugly as I need to put the newly constructed Long object into a HashMap and get the reference to the previously cached Long object. I believe providing this implementation will reduce my application memory requriements drastically as I need to cache huge volumes of data (around 1 GB of data need to be cached). Will there be any problems in providing an implementation like this ... Are there any better alternatives ?

Objects in general take somewhere in the region of 24-32 bytes to represent (excluding any member
variables) therefore Long will require somewhere in the region of 32 to 40 bytes to represent. The
hashMap you use to cache your Longs creates additional overhead (we'll ignore this for now as it can be
amortised over the individual unique Longs that you cache.
a long takes 8 bytes to store.
a reference takes 4 bytes (on a 32 bit machine 8 on a 64 bit JVM)
Therefore on 64 bit machines there is no advantage. Caching will always take more memory then using
native longs.
on a 32 bit VM the advantage of using cached Longs when compared to native longs occurs when you
have an average of at least 8 references to each unique Long. (for a large number of unique Longs)
However there are, I believe, plans to do this in 1.5. However they are not doing it to save memory. They
are doing it to improve the performance of autoboxing. Also the cache will not be dynamic it will be of
fixed size and created when the VM starts up. Basically values in the range -128 to 127 (or something
similar) will be cached for byte, short, int , long.
matfud

Similar Messages

  • Validating Cached Home Object

    We cache the home objects to save on jndi lookups. But if the home
    object belongs to a different application (something.ear), and
    something.ear gets redeployed, the cached home object is no longer
    valid.
    Was wondering if there's a way to validate the cached home object.

    Refer to
    http://dataml.net/articles/ValidateXMLSchema/part1.htm

  • Problem changing Long object's value

    Hi,
    I want to know what is the way to change the value of a Long object (if any).
    I didn't find set for this, and i want to change the value after creating the object withoud changing the reference (not by longObject = new Long(5)).
    Thanks,
    Snayit

    That's not possible. Long is immutable (as are String, and all other primitive wrapper classes). This is done because immutable objects have huge advantages in many cases (like when acting as the key to a hashmap).

  • How to cache the objects MANUALLY?

    hello
    some o-r mapping tools can cache the objects that have been queried,then next time these objects are required,it don't need to access the database again,it can also monitor the database updating.
    i wonder how i can implement such "cache" function MANUALLY? because i DON'T want to use ANY o-r mapping tools. i only use the jdbc to query database,then generate the object.
    who can give me some clue?? or articles? or sample codes??
    thank you!!!!!

    no you don't understand me,what i want to know is the
    mechanism of the cache,and how to implement it myself
    without using the o-r mapping tools.
    the dao pattern can encapsulate the database
    access,but it can NOT cache the object .First you need to define how the caching occurs.
    - Can the data in the database change without going through your code?
    - Are there multiple copies of your app running at the same time. If yes then what happens if one is updated?
    - How many of these can there be and what impact will this have on memory?
    - etc.
    You also need to identify the 'identity' of an object.
    A simple strategy....
    - Some layer requests an object using the 'identity'.
    - The database layer code looks in a hash for the 'identity'. If it finds it it returns it.
    - If it doesn't find it it uses a DAO to load it, then puts it in the hash, then returns it.

  • Efficiency of Long objects over Integer objects? any ?

    I have a Long object which actually only stores "integer" values and we had coded it that way long before we realised it. Now I am told we need to change the LONG object to INTEGER object to improve Java efficiency. I disagree with that. Note that we are not doing any ARITHMETIC operations on the Long object at all. I understand that it would be efficient to use Integer object if theres a lot of arithmetic operations being done on it. But since we are not how is converting of Long objects to Integer going to improve my efficiency? and moreover since only integer values are stored in the Long object I dont see any memory allocation lose too....am i right in my posture?
    Thanks

    Thanks for quick reply ! are you saying Long and
    Integer occupy same amount of memory space if the Long
    object contains integer value ?No.
    You said:
    moreover since only integer values are stored in the Long
    object I dont see any memory allocation lose too....am i right in my posture?I took that to mean that you thought that since the Longs contain a smaller (int-sized) values, that they're taking up the same space as Integers, and therefore you won't save any memory by switching to Integers.
    That's not in fact the case. A Long takes up the same amount of space regardless of whether it's holding 0 or 1 or Integer.MAX_VALUE or Long.MAX_VALUE, and that space is probably slightly bigger (2 bytes bigger, I'd guess) than what Integer uses.
    So technically, you will save some space (probably) by going to Integer. However, unless you have a huge number of these objects, that space savings will be minimal, and unless you've actually seen numbers in a profiler, it's pointless to speculate.

  • Set Java Object with Java Long Object from JNI

    Hi,
    i am getting crazy with the jni...
    in Java i have the follwoing:
    public class blabla{
    Object myObject;
    i chose Object cause the return value from native is not known
    in case for a long value i handle it like this :
    //get the Long class
    jclass LongCls = env->FindClass("Ljava/lang/Long;");
    jmethodID jmid = env->GetMethodID(LongCls, "<init>","(J)V");
    //create an Long Object with the long return value
    jobject LongObj = env->NewObject(LongCls,jmid,longreturnvalue);
    //set Long Objekt - doesnt work!(jclazz is the class of the return Object of the blabla class)
    jfid = env->GetFieldID(jclazz, "myObject", "Ljava/lang/Object;");
    env->SetObjectField( returnobjectofblabla,jfid,LongObj );
    the long value is set fine in the Long Object but i cant set the Long Object with the SetObjectField method into the Object myObject.
    Java is shown that the myObject contains a Long Object but the long value of the Long Object is totally wrong and doesnt equal to the long value which has been set.But setting the value works fine- any ideas or solutions?
    Thank you!

    charliess wrote:
    sometimes i really wonder about the answers in this forum - until now i got not one answer that helps me, even i tried to write down the problem very detailed...
    Sometimes I wonder about people who jump onto a site and immediately assume that
    1. They are the most important person in the world
    2. That they deserved the absolute undivided attention of absolute everyone.
    3. That everyone should be absolutely polite to them and provide them with perfect answers.
    4. Feel free to denigrate and posit their own opinion on everything while ignoring anything else that anyone else says.
    5. Expect that everyone else should understand their poorly worded questions.
    Myself I find such individuals extremely amusing. Although they seldom stick around long here. At least not under their original alias.
    plaz tel me how to realise your error checking?example plz
    You start by having at least a basic understanding of C/C++ and java.
    Then you read the JNI documents, all of them, for each method that you are using.
    Then you write code such that it actually reflects the documents. For example you check return types. And probably deal with the possibility that JNI methods might throw exceptions.
    as far as i know the jni methods like getfieldids and so on throw exceptions other like stObject dont do that the just return nothing
    i can see all exceptions in my Java console thats not the Problem, setting the Long Object does not throwing a exception btw->
    Myself I wouldn't expect that a JNI exception would show in the java console. Could I suppose though.
    However nothing so far would suggest that an exception is being thrown. That however doesn't alter the fact that you must still write the code such that it could happen.
    is it possible in general to set an java Long Object created in C(native) into a Object type (Object) overgiven as parameter in my JNI function with the setObject method?
    Is it possible that you could actually follow my previous request and create some code that actually runs instead of cut and pasting whatever you feel like?
    plz answer also with code and examples i did the same for you...No you didn't. You posted something which would not compile and quite possibly doesn't represent your actual code at all.
    And please note that we do not get paid to do this. If you want to pay someone to solve your problem then there are sites for that.
    Paying someone allows you to make all sorts of demands. The more you pay the more people will put up with.
    If you don't want to pay and do in fact want free answers then it will probably be in your interest to
    1. Be polite
    2. Answer the questions that have been asked of you.

  • How can I cache an object for unlimited time or for ever.

    Hi,
    How can I cache an object for ever or unlimited time. What values should be used to in cache-config.xml i.e.
    <expiry-delay system-property="tangosol.coherence.zerostage.expiry.delay">XXXms</expiry-delay>
    <flush-delay system-property="tangosol.coherence.zerostage.flush.delay">XXXms</flush-delay>
    thanks a lot in advance.

    Hi Suhas,
    If you look in the documentation http://download.oracle.com/docs/cd/E14526_01/coh.350/e14509/toc.htm and more specifically here http://download.oracle.com/docs/cd/E14526_01/coh.350/e14509/appcacheelements.htm#BABDHGHJ you will see the explination for the two configuration items you mention.
    The default expiry-delay is zero which means no expiry - that is the data will stay in the cache forever (or until you do a remove). If expiry is zero then flush-delay has a default of zero is used and automatic flushes are disabled.
    JK

  • Writing LONG objects to DB

    How can I write large LONG object to DB using a sql-procedure?
    I invoke form java a procedure, which takes a LONG-parameter. This procedure simply writes LONG-parameter to DB.
    Using a procedure I can't write large objects, I can write only <4Kb. I tried to send 10Kb and reseived SQL-error:"can bind a LONG value only for insert into a LONG column".
    Please, help,
    thanks for listening

    Hi 398287,
    Sorry but I can't help you, based on the [lack of] information you have provided. Perhaps if you would provide the following details, I may be able to help you:
    1. Complete error message (and stack trace).
    2. The part of your code that you think is causing the problem.
    3. Environment details (Oracle version, java version, platform, etc.)
    Good Luck,
    Avi.

  • Prevent the browser to read cached Flash object

    I have a slideshow Flash object which pics filename are
    supplied by an .XML
    file created dinamically every time the page loads.
    Unfortunately the .SWF is always being read from cache even
    though the .XML is changed
    correctly. The Flash movie always shows the pictures loaded
    at start of the application.
    I am able to refresh the Flash movie if:
    - I restart the application;
    - I set the browser setting to check for newer version of
    stored pages to "every time";
    - after 5/10 minutes have elapsed from the last reloading
    (couldn't find a real pattern here);
    To prevent caching I have tried the following:
    - Added a random number at the and of the URL that calls the
    page (...&r=#rundomNumber()#)
    - Added <META HTTP-EQUIV="Expires" CONTENT="Mon, 04 Dec
    1999 21:29:02 GMT">
    - Added <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    - Added <META HTTP-EQUIV="Cache-Control"
    CONTENT="no-cache">
    in various combinations.
    - Used <cfheader name="Expires"
    value="#GetHttpTimeString(Now())#">
    - Modified the param name="movie" to
    <param name="movie"
    value="Gallery.swf?id=#randomNumber()#" />
    or to
    <param name="movie"
    value="Gallery.swf?id=#randomNumber()#&xmlPath=gallery.xml&id=#randomNumber()#"
    />
    also
    Opening the Gallery.fla with Flash 2004 in the Component
    Inspector, parameter xml Path = gallery.xml changed to
    "gallery.xml?id=1"
    or
    "gallery.xm?Math.round(Math.random() * 99999
    all this to prevent the browser to read from cache and
    download a fresh copy from the server, but to no avail.
    Is there something else to be tried?
    Thank you for helping.
    ContiW

    Click in your page where you want the SWF to go, then select
    Insert > Media > Flash from the menu (or maybe Insert >
    Flash ... DWMX goes back a way).
    Charles Nadeau
    Dreamweaver
    Adobe Systems

  • How to Filter & Sort on Cached view object data?

    We are using JDeveloper 9.0.3.4 and implemeting a Struts/JSP application that query's via view object on one table. Is it possible to sort and order by on the view object's cached data? How does one do this?
    Thanks
    Natalie

    As for filtering rows, there are two ways:
    1. In the VO that's sorting data (in my article), you can add logic to skip unmatching rows in the following methods:
    protected boolean hasNextForCollection(Object qc)
    protected ViewRowImpl createRowFromResultSet(Object qc, ResultSet resultSet)
    2. In the base VO (unsorted), you can apply a RowQualifier. For example,
    oracle.jbo.server.RowQualifier rowQual = new oracle.jbo.server.RowQualifier("EmpDeptNum = 20");
    myVO.setRowQualifier(rowQual);
    Thanks.
    Sung

  • Distributed Cache - large objects

    Hi,
    I have a need to store a large collection of object associated with one key in the cache. And updates to the cache will happen with one of the object in the collection.
    How does coherence handle the sync b/w the distributed cache -- will it be like the whole collection marked dirty and synched again or just the bits that got changed. Ours is a perf intensive application so would like to know the implications of the same.
    Thanks in advance for your suggestions.
    - Anand

    Hi Anand,
    You can use InvocableMap (also see Provide a Data Grid for this - a very simple example is attached.
    Regards,
    Dimitri<br><br> <b> Attachment: </b><br>Main.java <br> (*To use this attachment you will need to rename 295.bin to Main.java after the download is complete.)

  • Visio UML - Long object lifetime run out of connector points

    I have a sequence diagram that is attempting to model a relatively long business process over a large number of objects.
    the problem is that as I extended the object lifetime swimlane I run out of connector points the automatically appear on the line, so I cannot attach a new activation shape.
    How can I get more connector points to be automatically drawn on the line.  I have been unable to use the Connection Point tool (Shift+Ctrl+1) to put new connection point directly on the swimlane, it keeps snapping to the grid lines and not to the line.
    Cheers...
    Robert

    Hi,
    If you are trying to create a point-to-point connection and having a difficult time gluing a connector exactly where you want it, try different snap and glue settings:
    On the View tab, Visual Aids group, click the
    Snap & Glue dialog box launcher, select the options that you want.
    More reference: "Add, move, or delete connection points"
    http://office.microsoft.com/en-us/visio-help/add-move-or-delete-connection-points-HP010378181.aspx?CTT=1
    Best regards.
    William Zhou
    TechNet Community Support

  • UnitOfWork/Cache/ClientSession Object Update Problem

    I have a test case that does a create, read, update, read. This is done through methods on a stateless session bean with all methods requiring a transaction.
    I am using Toplink 9.0.3,JBoss 3.0.7 and JTS. Bascally I have a very simple object.
    1. I create the object then call my bean, my bean
    calls TopLink and gets a ClientSession from a
    ServerSession and then gets a UnitOfWork from the
    clientSession. I then register the object as new,
    and commit the object, which get's written to the
    database. My bean method returns the pk.
    BeanInterface.createObject(Object obj) {
    UnitOfWork uow = Singleton.getServerSession().getClientSession().getUnitOfWork();
    uow.registerNewObject();
    uow.commit();
    2. I then read the object via my bean, by calling
    get ClientSession from ServerSession and calling
    readObject on it.
    BeanInterface.readObject(Object obj) {
    ClientSession session = Singleton.getServerSession().getClientSession();
    return Utility.cloneObject(session.readObject(obj)); //Insures I am getting my own copy not a ref.
    So far so good.
    3. I then modify the object in my client and call
    an update method on my bean. This methods does a
    SessionServer.getClientSession().getUnitOfWork()
    I then register my object as existing, deep
    merge it and then commit the unit of work.
    BeanInterface.updateObject(Object obj) {
    UnitOfWork uow = Singleton.getServerSession().getClientSession().getUnitOfWork();
    Object clone = uow.registerExistingObject(obj);
    uow.deepMergeClone(obj);
    uow.commit();
    I check the database and the changes are there.
    4. Now the kicker. I read the object again like in
    step 2 and I get the original object not changes.
    So what is in the cache is the orignal object,
    wht is in the database is the modified object.
    BeanInterface.readObject(Object obj) {
    ClientSession session = Singleton.getServerSession().getClientSession();
    return Utility.cloneObject(session.readObject(obj)); //Insures I am getting my own copy not a ref.
    At this point I am stumped because the changes are in
    the database, but not in the cache and I get no
    exceptions.
    Any thoughts?
    Thanks
    Mike H. SR.

    Donald,
    There are three methods you can use. registerExistingObject(), registerNewObject(), registerObject(). If you know that the object is new then using registerNewObject() is better because it does not do the existence check. If you know that that object exists then using registerExistingObject() saves you the overhead of having TopLink determine whether the object exists or not. registerObject() is really only useful if you do not know whether the object is new or exists. So registNew, registExisting are optimizations. In my case we are using registerNewObject() when a consumer says create the object, and registerExistingObject() when they are doing an update. There is also a store, which uses the registObject(), in this case the consumer does not know whether the object is new or existing.
    I have been tracking the register method in my debugger and the problem may be in this method. Basically the registerObject or registerExistingObject is suppose to load the original object from the datbase if it is not in the cache. If it is in the cache is should clone it giving back the reference to the clone. In the end there will be two copies of the object the Clone on the cloned object list and the original on the original object list. The deepMergeClone should update the clone with the latest changes and then commit should be deltaing the clone and the original to determine what goes to the db. So far the is working ok because the data does filter to the database. If I turn caching off there are no problems.
    Additional information. I did some testing and watching in the debugger, I know this, if I do a serverSession.getClientSession.readObject() or any select or read on the clientSession I get back the same reference every time, but serverSession.getClientSession().acquireUnitOfWork().readObject() returns a different object reference than the clientSession. This may be by design, also I believe the problem is the descriptor, but I cannot figure out what it is about the descriptor, because this only happens on a few descriptors.
    By the way I tried the registerObject prior to posting to no avail and had it worked that would have meant there was a problem with registerExistingObject, because this is an existing object.
    Thanks for the input.

  • Portlets cannot cache longer than 15 minutes

    We cannot cache portlets longer than 15 minutes regardless of programmatic or administrative settings. We're running G6 on Windows.
    Wondering if anybody else is also experiencing this?

    Hey,
    If you press 'A' the 'set audio record path' window should come up, in that window you should be able to change the maximum record time from 15 minutes to whatever you want
    Hope this helps
    Regards

  • Query based on a Long Object Datatype

    I have a query like this
    SELECT project
    FROM vgn_ci
    WHERE bobdb__val
    LIKE '%#8#ObjectID,#7#%'
    Over here the the bobdb__val is of type long so it cannot be used with where clause, hence this query won't work. Can anybody provide me a solution.
    null

    I don't know which version of data base
    you are using.
    If you have 8i version you can use
    Oracle package DBMS_LOB to convert Long to Clob.

Maybe you are looking for