Performance issue ! all java guru invited

hi !
plz let me know is there any performance related difference between these two approachs
mention below.
Ist
public void method1()
for(int i=0;i<20;i++)
String temp = "str"+i;
myObject mobj = new myObject();
2nd
String temp="":
myObject mobj=null;
public void method1(){
for(int i=0;i<20;i++)
temp = "str"+i;
mobj = new myObject();
}

Find out! Get the loop to run 20000 times and time each using System.currentTimeMillis(). Repeat this several times for each, throw away the highest and lowest couple of results and average the rest. Compare this between the two approaches.
Regardless, the performance difference is likely to be minor, if any, compared to the construction and allocation of memory for the new Objects. I would hope that most reasonable compilers would be able to deal with these anyway.
Performance issues aside, many people prefer the former approach since each local variable doesn't outstay its welcome. This makes debugging and refactoring more straightforward. As with all optimisations, it's not worth making them at the expense of clarity if they make no real difference.
Test the performance of your code, in the context of your application, in realistic circumstances. You'll soon find out where your effort should be spent on optimisations.
Hope this helps.

Similar Messages

  • Performance Issue Of Java Application on Pentium 4

    Dear All
    I have finished an application program, which runs smoothly in PC with Intel Pentium 3 Processor with high performance, but the performance is highly decreased with Intel Pentium 4 Processor. Is it a limitation of Java?
    Im using MS Access database.
    I have restructured the queries but the performance is highly enhanced in P3 but it degrades and sometimes there is no consistency in the performance timmings in P4.
    System Configuration are:
    P3 : 256 MB RAM with Windows 2000 SP2,MS ACCESS 2000
    P4: 256 MB RAM with WIN 2000 SP2,MS ACCESS 2000
    Is there any solution to this problem?
    Pls help!
    Best Regards
    Sourav

    256MB of RAM for a Windows 2000 machine?!?
    You're probably swapping memory.
    - Go into Task Manager and see what is running on each machine.
    ...and see if you can not start up some things.
    - See how much memory you have Available on each BEFORE you run the app.
    - use java -Xmx option to specify less than the available memory you have.

  • Performance issue on Java Stored Procedure

    I have converted the Stored Procedures into JSP with SQLJ. I
    loaded the classes (not the source) onto Oracle 8i Database and
    published within tbe stored packages. What I found out was the
    performance is about 12 times on average slower than the PL/SQL
    stored packages when I made calls to JSP. I am not surprise JSP
    is slower than PL/SQL but can we improve by tunning the Java
    codings or VM within the 8i database?
    null

    James Chan (guest) wrote:
    : I have converted the Stored Procedures into JSP with SQLJ. I
    : loaded the classes (not the source) onto Oracle 8i Database and
    : published within tbe stored packages. What I found out was the
    : performance is about 12 times on average slower than the PL/SQL
    : stored packages when I made calls to JSP. I am not surprise JSP
    : is slower than PL/SQL but can we improve by tunning the Java
    : codings or VM within the 8i database?
    all user written java code in the 8i rdbms is currently running
    as bytecode in the jvm.
    a future release will provide a component called "Native Compiler
    [NCOMP]" so it should run considerably faster then.
    see the following link for details :
    http://technet.oracle.com/files/search/search.htm?ncomp
    null

  • Performance ISSUE of JAVA Code

    Hello,
    We are having Delphi application. But as per our requirements we have to migrated the Delphi code to java. We have done this but it is consuming the 3 times more time as compare to Delphi Application.
    We have used simple primitive types and arrays. But there are some loops which runs 4-8lac (800000) times.
    Colud you please suggest me some ways to improve the performance, as it is very critical for me ?
    Thanks,
    Satbir

    We have done this but it is consuming the 3
    times more time as compare to Delphi Application.
    We have used simple primitive types and arrays. But
    there are some loops which runs 4-8lac (800000)
    times.Sometimes trying too hard will make things slower.
    I have some suggestions:
    1) Do not inline functions yourself. This will in the best case have no effect and in the worst case make your code buggy. If your code is written according to good object-oriented methods it is probably not even possible.
    2) Don't flog the garbage collector. If your inner loop creates new objects, don't release them for the collector to clean up. Instead put them in a free list and reuse them. For general coding this isn't such a great idea, because the collector can reclaim objects about as efficiently as you can recycle them yourself. But inside a tight loop it can help a lot.
    2.1) Objects with finalizers are slow to garbage collect. Avoid finalizers in performance-critical code. (You can use classes that have finalizers, you just don't want them to be garbage collected while in tight code). Some of the classes provided by the Java API have finalizers also.
    3) Try using the server VM.
    4) Try different versions of the JDK. Some people have found that 1.4 is slower than 1.3, others find it is faster. Both are much faster than 1.2.
    5) String operations in Java are very slow. Much slower even than they usually are. StringBuffers can be 4-5 times faster than Strings, but even then string handling is just not fast. See if you can minimize the amount of string handling in your tight loops.
    6) Synchronization is quite slow also. It is faster in 1.4, but it is still slow. Don't synchronize unless absolutely necessary. Some synchronized operations can be done instead with volatile variables, unfortunately many things cannot.
    7) Make sure you have enough heap space for everything to fit comfortably. If the garbage collector is running during a tight loop, this will kill your performance.
    8) Some of the calls to the Java API are very slow. Some standard API classes, such as Hashtable, have synchronized methods, which can cause hidden slowing. Other functions are just plain slow in general.
    9) Try using the -Xrunhprof option to profile your code. While it will run much more slowly with the profiler enabled, it will at least indicate where the slowness is. It might not be what you expect.

  • Performance issue: Java and XSLT

    I have a performance issue concerning Java and XSLT: my goal is to transform an xml file (source.xml)
    by using a given xsl file (transformation.xsl). As result I would like to get a String object, in which the result
    of the transformation (html-code) is in, so that I can display it in a browser. The problem is the long time
    it takes for the code below to run through.
    xml = new File("C:\\source.xml");
    xmlSource = new StreamSource(xml);
    xslt = new File("C:\\transformation.xsl");
    StreamSource xsltSource = new StreamSource(xslt);
    TransformerFactory transFact = TransformerFactory.newInstance();
    trans = transFact.newTransformer(xsltSource);
    StringWriter stringWriter = new StringWriter();
    StreamResult streamResult = new StreamResult(stringWriter);
    trans.transform(xmlSource, streamResult);
    String output = stringWriter.toString();
    stringWriter.close();
    Before, I made the same transformation in an xml development environment, named Cooktop
    (see http://xmlcooktop.com/). The transformation took about 2 seconds. With the code above in Java it
    takes about 20 seconds.
    Is there a way to make the transformation in Java faster?
    Thanks in advance,
    Marcello
    Oldenburg, Germany
    [email protected]

    I haven't tried it but the if you can use java 6, you could try the new stax (StAX) with the XML stream loading..
    Take a look at:
    http://javaboutique.internet.com/tutorials/staxxsl/
    Then, you could cache the xslt in templates:
    ---8<---
    templates = transformerFactory.newTemplates( xsltSource );
    Transformer transformer = templates.newTransformer();
    (here you could probobly also cache the Transformer object but I think it's it's not thread safe so it's a little tricker..)
    StreamResult result = new StreamResult( System.out );
              transformer.transform(xmlSource, result);
    And, don't transform your result to a string, use a Stream or something, then the transformer could start pumping out html while working, and if you get a out of memory error it looks like you have a pretty big xml file...
    If you use jsp you could try the build in jsp taglib for xml which I think is rather good and they have support for varReader which implements the StreamSource iirc.
    /perty

  • Performance problem with java stored procedure

    hi,
    i developped a java class, then I stored it in Oracle 8.1.7.
    This class contains several import of other classes stored in the database.
    It works, but the execution perfomances are disappointing. It's very long. I guess, that's because of the great number of classes to load that are necessary for my class execution.
    I tried to increase the size of the java pool (I parameter 70 Mo in the java_pool_size parameter of the init.ora), but the performance is not much better.
    Has anyone an idea to increase the performance of this execution of my class ?
    In particular, is there a way to keep permanently in memory the java objects used by my class ?
    Thanks in advance
    bye
    [email protected]
    null

    before running Java, the database session needs to be Java enabled; this might be the reason why it is taking so long. If this is the case, you should see an improvement in subsequent calls, once a database session is Java enabled, other users can benefit from it.
    Kuassi
    I have some performance issue with java stored procedure. Hope some one will be able to help me out. I'm using java stored procedures in my application and basically these procedures are used to do some validation and form the XML message of the database tables. I have noticed that when I call the PL/SQL wrapper function, it is taking time to load the java class and once the class is loaded the execution is faster. Most of the time is spent for loading the class rather than executing the function. if I reduce the class load time, I can improve the performance drastically. Do any one of you know how to reduce the class load time. The following are the platform and oracle version.
    O/S: IBM AIX
    Oracle: 8.1.7

  • Performance Issue in UNION ALL....

    Hi,
    I have a performance issue in a query using select.. union all .
    There are few select statements which are joined by union all.
    I need to re-frame the query such that the records from each individual select
    statement can be appended into a collection variable.
    I need to avoid the use of UNION ALL.
    Can anyone please help me out in this issue?
    Please find the select statement below.
    SELECT *
    FROM v_gfd1_asset_allocation
    WHERE NVL(value,0) <> 0
    AND scheme = p_scheme_id
    UNION ALL
    SELECT *
    FROM v_gfd1_capitalization_alloc
    WHERE NVL(value,0) <> 0
    AND scheme = p_scheme_id
    UNION ALL
    SELECT *
    FROM v_gfd1_currency_allocation
    WHERE NVL(value,0) <> 0
    AND scheme = p_scheme_id
    Thanks,
    Santhosh

    The UNION ALL takes the result set of one query, appends the result set of the next, and so forth. No sorting or filtering takes place. So, as each query has to be executed to completion, I do not think there is another way - that is what union all is for.
    You would probably do well to examine each query's access path. Would an index on NVL( value, 0 ), scheme help, for instance? Understanding the data distribution in the table and how it affects the execution plan would help you improve query performance.

  • TS3694 I am using iphone 3gs, I upgraded my i-os to 6.0 from 5.1.1 however I am facing performance issue, along with this all the applications including settings or any other shuts down automatically. Is there any way by which I can use my phone in better

    I am using iphone 3gs, I upgraded my i-os to 6.0 from 5.1.1 however I am facing performance issue, along with this all the applications including settings or any other shuts down automatically. Is there any way by which I can use my phone in better way?

    No, downgrading from any version of iOS to an earlier version is not supported.

  • WEBUTIL - Does adding it to all forms cause performance issues?

    If I add the webutil library and object library to all forms in the system (as part of a standard template) despite the fact most won't use it, will this cause any performance issues???
    Thanks in advance...

    The webutil user guide has a chapter on performance considerations. Have you looked at that?
    The number one point from that chapter is:
    1. Only WebUtil Enable Forms that actually need the functionality. Each form that is WebUtil enabled will generate a certain amount of network traffic and memory
    usage simply to instantiate the utility, even if you don’t use any WebUtil
    functionality.

  • Difference between all-java & win-performance pack?

    Hi,
    Exactly what's the difference between the all-java JMF and the windows performance pack? In terms of files?
    TIA,
    Reggie

    A few features are completely unavailable on all-java, most notably capture. Other than that, it's a matter of some formats and codecs not being available (eg, MPEG-1). The list of supported media types on the JMF home page should pretty much spell it out.
    --invalidname

  • Performance issues with the Vouchers index build in SES

    Hi All,
    We are currently performing an upgrade for: PS FSCM 9.1 to PS FSCM 9.2.
    As a part of the upgrade, Client wants Oracle SES to be deployed for some modules including, Purchasing, Payables (Vouchers)
    We are facing severe performance issues with the Vouchers index build. (Volume of data = approx. 8.5 million rows of data)
    The index creation process runs for over 5 days.
    Can you please share any information or issues that you may have faced on your project and how they were addressed?

    Check the following logs for errors:
    1.  The message log from the process scheduler
    2.  search_server1-diagnostic.log  in /search_server1/logs directory
    If the build is getting stuck while crawling then we typically have to increase the Java Heap size for the Weblogic instance for SES>

  • Date Performance issue

    hi Guru's,
    I am using 11.1.6.8 OBIEE. One of my report is having performance issue when i dig into that i found that the date filter not applied in the SQL generated to send DB, due to that it is doing table scan, But strange thing is that when it displaying  data based on the Date range filter. It is only happening with the date dimension all other dimensions are working fine. I am not sure what it is missing.
    Thanks In advance.
    regards
    Mohammed.

    hi Saichand,
    Thanks for taking time and looking into.
    The filter is applied on the logical query but the physical query send to the DB is not having the filter. Due to that it is doing full table scan of the fact table and almost 30 minutes to display data. I am not sure why the physical query is not having the date filter. when i add the location or other type of filter it added to the Physical Query send to DB.
    regards
    @li

  • Socket based application - Performance Issues - Suggestions Needed

    Hi All,
    We have an application which basically has been developed using core java. Here is a high level information about the application:
    a) It opens a serversocket which allows clients to connect to it.
    b) For every new client connection, a separate thread is created and this thread deals with requests from clients, processing the data and replying back to clients.
    c) Each socket is polled continuously and sockettimeout is 2 seconds. If there is a timeout, we handle the situation and socket is again read. So basically sockets is read every 2 seconds. If number of timeouts reaches a configurable value, we close the connection and thread is dropped as well.
    d) In production, three instances of this application are running with the help of a cisco load balancer. It is there for last 5 years.
    However there has always been some minor performance isssues and we have sorted them out using different types of garbage collectors, by introducing hardware load balancers, upgrading the code for new Java versions. It is currently running on 1.4.2.
    However there has always been some performance issues and today while googling over internet I came across following on the bea website which says that core java sockets are not as efficients as native API. BEA has implemented its own APIs for weblogic. My queries are:
    a) Are there any better Java Socket/network API (for solairs, I know Java is plateform independenet but there could be lib which also using native libs) which are much more efficient than Core Java.
    b) We are getting the InputStream/OutputStream and creating objects of DataInputStream/DataOutputStream to read the data 'Byte-By-Byte'. Each byte can have different information thats why it is required. Are there any better way of getting info than what we are currently doing.
    c) As I mentioned, we are continously polling the socket for read operation with a timeout value of 2 seconds. What is the better among the following from performance point of view: (1) Frequent read operation with a lesser timeout value or (2) Less Frequent read operations with larger timeout value. (3) Any better idea??
    Please suggest few things or pointers which I could do to improve the performance of the applcations. Many thanks.
    Thanks,Akhil
    From BEA website:-
    "Although the pure-Java implementation of socket reader threads is a reliable and portable method of peer-to-peer communication, it does not provide the best performance for heavy-duty socket usage in a WebLogic Server cluster. With pure-Java socket readers, threads must actively poll all opened sockets to determine if they contain data to read. In other words, socket reader threads are always "busy" polling sockets, even if the sockets have no data to read. This unnecessary overhead can reduce performance."

    My recommendations:
    - Always use a BufferedInputStream and BufferedOutputStream around the socket streams
    - Increase the socket send and receive buffers to at least 32k if you are on a Windows platform where the default is a ridiculous 8k, which hasn't been enough for about 15 years.
    - Your 2-second timeout is far too short. Increase it to at least 10 seconds.
    - Your strategy of counting up to N short timeouts of S seconds each is completely pointless. Change it to one single timeout of N*S seconds. There is nothing to be gained by the complication you have introduced to this.

  • How to restrict logging on portal (Performance issue)

    Hi guys,
    does anyone know how to restrict logging of the portal? Even though I made a change on Visual Administrator -> Services -> Log Configurator setting ALL categories to severity = 'Error', I keep getting 'Info' severity traces logged in defaultTrace.trc (viewed by Logg Viewer). Which in practise means tons of logged trace information! I think this might be one of the reasons we have been experiencing performance issues lately.
    Does anyone know how to restrict this logging?
    Any help greatly appreciated!
    Cheers,
    Frank

    Hi,
    I would not only set the severity of categories to 'Error' but also locations to 'Error'.
    A log controller - can be a "category" or a "location".     Categories are used for "logging" and represent problem areas such as network, database, security, user interface, etc. Identified by a slash-separated ('/') path of names, prefixed with an additional slash.     Locations are used for "tracing" and correspond to places in the development components. Identified by a dot-separated ('.') path of names, which is often the name of the respective java package.
    Greetings,
    Praveen Gudapati

  • Performance issues related to logging (ForceSingleTraceFile option)

    Dear SDN members,
    I have a question about logging.
    I like to place my logs/traces for every application in different log files. By doing this you have to set the ForceSingleTraceFile option to NO (in the config tool).
    But in a presentation of SAP, named SAP Web Application Server 6.40; SAP Logging and Tracing API, is stated:
    - All traces by default go to the default trace file.
         - Good for performance
              - On production systems, this is a must!!!
    - Hard to find your trace messages
    - Solution: Configure development systems to pipe traces and logs for applications to their own specific trace file
    But I want the logs/traces also by our customers (production systems) in separate files. So my question is:
    What are the performance issues we face, if we turn the ForceSingleTraceFile option to NO by our customers?
    and
    If we turn the ForceSingleTraceFile to NO will the logs/traces of the SAP applications also go to different files? If so, then I can imagine that it will be difficult to find the logs of the different SAP applications.
    I hope that someone can clarify the working of the ForceSingleTraceFile setting.
    Kind regards,
    Marinus Geuze

    Dear Marinus,
    The performance issues with extensive logging are related to high memory usage (for concatenation/generation of the messages which are written to the log files) and as result increased garbare collection frequency, as well as high disk I/O and CPU overhead for the actual logging.
    Writing to same trace file, if logging is extensive can become a bottleneck.
    Anyway it is not related to if you should write the logs to the default trace of a standard location. I believe that the recommendation in the documentation is just about using the standard logging APIs of the SAP Java Server, because they are well optimized.
    Best regards,
    Sylvia

Maybe you are looking for

  • Routine - get char 2 to 5 from the source value

    Helo friends, I have a requirement like below i have a char and data type is numeric(5) and value of the char is A1234 now i need to load the data to DSO with value 1234 , since its datatype is numeric and i have to ignore 1st value i.e.  'A' so, i h

  • How can I sync my new iPhone 4S to calendar, contacts, and photos on my MacBook?

    Just bought my first iPhone after 2 years as an Android user. My 2008 MacBook would never talk to the Android, but now - they tell me - I can backup my phone onto my computer and share contacts, calendar and photos with the computer. I've plugged the

  • Limited Admin Privileges/Specific Elevation of User Accounts

    I'm hoping to create an account on my laptop for my roommate.  I don't want him to have a full admin account, but he knows enough about computers that he could troubleshoot networking, and I want to enable him to install programs on the system.  I'm

  • Material planning field in Activity

    Hello All When we select activity and go in detail screen, go to assignments tab - there will be a material planning field. I am not able to see that field, is that a configuration , if yes where is the setting. Thanks, Karthik Edited by: SG_Karthik

  • Menu bar disappears

    How do I get the menu bar from raising up after i move my mouse off of it ?  Not even sure I'm asking the question correctly, but on any web page, when I mouse up to the top, the "menu" bar drops down and I see "Safari, file, edit, view......etc".  I