Java Performance question...

Hi,
I am trying to find information/tips to help me improve overall Java and thread performance using j2sdk 1.4.2 or at least verify I am following good practices regarding performance. I have seen some articles that mention issues w/ synchronized elements, avoiding exception throwing, etc., I still have questions as to if and how the following afffect performance:
- yield() vs. sleep() vs. wait() (or none) for maximizing thread execution time/efficiency
- join() vs. wait() + isAlive()
- static vs. instance methods/data
- Running threads as classes that extend Thread vs. implement Runnable
- ... anything else I may be missing at the moment
Do any of these things even matter?
What about JVM command-line arguments and performance? Is there comprehensive explanation somewhere detailing all options and guidelines on what values to use?
It seems like all of this must have been written about/discussed before, but I haven't seen anything that helps pull it all together so I don't have to experiment with it myself (i.e., reinvent the wheel).

practices regarding performance. I have seen some
articles that mention issues w/ synchronized
elements, avoiding exception throwing, etc.,Take those with a grain of salt.
Sync: Try to keep your synchronized blocks short--get in and get out. This minimizes contention. But don't avoid syncing when you need it or convolute your code just because you think syncing will hurt performance.
Exceptions: If you're throwing so many exceptions that it's significantly hurting performance, you've got bad data, a stupid user, buggy code, a bad network, etc. Avoiding exceptions won't fix that. Throw an exception when it's called for. By definition it should be exceptional, so it won't have a big impact on overall performance.
I still
have questions as to if and how the following afffect
performance:None of the following choices would be made for performance reasons.
>
- yield() vs. sleep() vs. wait() (or none) for
maximizing thread execution time/efficiencyAll of the above serve different purposes. Choose the one that's right for what you're trying to accopmlish.
Yield is for when you want to explicitly give other threads a chance to run. There's no guarantee the will. I've never used it, and I think I've heard that it's rarely usefule and can actually hurt performance a bit, probably because you shouldn't try to outsmart the scheduler.
Sleep is for when you want your thread to stop executing for a certain amount of time.
Wait is for when you want your thread to stop executing until some external event tells it to go back to work.
- join() vs. wait() + isAlive()Join just says stop here until the thread in question exits. I can't think off the top of my head when you'd use wait() + isAlive(), but I doubt there's any performance reason to chose it over join() to accomplish the same task.
- static vs. instance methods/dataNo.
Use static members for things that apply to the class as a whole, and have no need to use or modify the state of a particular instance of the class. Use instance members for things that are related to specific instance--i.e. this Foo as opposed to that Foo. Absolutely DO NOT pick one or the other thinking you'll get better performance.
- Running threads as classes that extend Thread vs.
implement RunnableAre you modifying or adding to Thread's behavior? Almost certainly no. Therefore, your class IS-NOT-A Thread, so don't extend Thread. Implement Runnable. This has nothing to do with performance.
- ... anything else I may be missing at the moment
Do any of these things even matter?It sounds like you're falling into the premature optimization trap.
Use appropriate algorithms and data structures to get maximum performance. Don't futz around with little bitty tweaks that go against good OO or the nature of your design until and unless you have measured the time these sections of code are taking and have verified that they are bottlenecks.
>
What about JVM command-line arguments and
performance? Is there comprehensive explanation
somewhere detailing all options and guidelines on
what values to use? The main things that you tweak on the command line in this respect relate to GC, I think.
http://java.sun.com/docs/hotspot/

Similar Messages

  • Java performance questions

    I'd like to know if there are any performance issues with the following practices:
    1.using import java.util.* vs importing only the specific files needed.
    2. using 30 - 40 character class, method and variable names. Wouldn't a shorter name be more efficient?
    3. is it a good idea to use static final variables instead of literal strings even if the string is only used once or twice in a class?

    I'd like to know if there are any performance issues
    with the following practices:
    1.using import java.util.* vs importing only the
    specific files needed.No, this has no effect on the performance once the code is compiled. It is little or no effect on the performance of compilation. The import itself does nothing other than to identify new classes or packages that can contain names not known within the current class, package or the java.lang package.
    2. using 30 - 40 character class, method and variable
    names. Wouldn't a shorter name be more efficient?Not really. The names are used during class loading (and reflection calls), but the effect this has on any interesting program is minor. Do not force the use of short names as it will cause developers to make very stupid tradeoff between mythical performance and quality. Instead, stress that names should be extremely clear but concise. True, one tends to run across really long (greater than 30 characeter) names infrequently, but if that is the clearest and most concise name for something, then that is the name you should use.
    3. is it a good idea to use static final variables
    instead of literal strings even if the string is only
    used once or twice in a class?There is no performance penalty to using multiple literal strings with the same value in the same class as the compiler will identify the duplication and ceate a single interned String. Instead, use static final String constants when there is some likelyhood the value may need to change (everywhere you use it) or that a more explanatory name needs to be sued. For instance, UNKNOWN_DEPARTMENT is better than "9999".
    I've seen folks use static finals of the form static final String BLANK = "" or static final String SPACE = " ". I can't see the value of it.
    Chuck

  • Swing performance question: CPU-bound

    Hi,
    I've posted a Swing performance question to the java.net performance forum. Since it is a Swing performance question, I thought readers of this forum might also be interested.
    Swing CPU-bound in sun.awt.windows.WToolkit.eventLoop
    http://forums.java.net/jive/thread.jspa?threadID=1636&tstart=0
    Thanks,
    Curt

    You obviously don't understand the results, and the first reply to your posting on java.net clearly explains what you missed.
    The event queue is using Thread.wait to sleep until it gets some more events to dispatch. You have incorrectly diagnosed the sleep waiting as your performance bottleneck.

  • Java Performance: Linux vs Windows, 64 bit vs 32 bit JVM

    I am looking for information about how Java performs on Linux vs Windows and how the results are affected when a 64 bit jvm is used.
    Disk access or IO are not important, I would really like to see some benchmarks on floating point arithmetic and/or heavy memory access, assuming that on all environments enough physical memory could be addressed so the extra available memory space for 64 bit os'es/jvm's is not important.
    I have been searching on Google but didn't find any useful recent results, only some very old stuff.
    Does anybody know how the OS and the JVM affect performance? I could imagine that Java VM's are a little less optimized on Linux because of the fact that Linux has a smaller marketshare, but maybe that is not true?
    Also I could imagine that 64 bit JVMs could be faster because they could use more cpu registers, on the other hand they could slow down a little because all memory pointers are twice as long so more data should be processed?
    Any comments are greatly appreciated!

    On the Linux vs Windows theme, you would probably find out, after much browsing & research, that there is no difference in performance or that the difference is too small to be even considered.
    On the 32-bit vs 64-bit subject, here's a recent blog that you could look at:
    http://dev2dev.bea.com/blog/patel_jayesh_j/archive/2007/09/32bit_or_64bit.html
    That blog has some links to some benchmarks, but here again, the differences are unlikely to be earth-shattering.
    Not much to add here, other than the most important improvement in performance derive from how the application is designed, and in some cases, how the JVM heap itself is configured, independently on Linux vs Win or 32 vs 64 -bit considerations.
    In a case when you would really need to know, there is no general right answer to your question, and you'd have to benchmark your specific application yourself in your specific execution environment to be able to evaluate possible benefits of 64-bit vs 32-bit.
    In conclusion, I wouldn't waste much time on all this, and you probably have better things to do yourself.

  • Simple performance question

    Simple performance question. the simplest way possible, assume
    I have a int[][][][][] matrix, and a boolean add. The array is several dimensions long.
    When add is true, I must add a constant value to each element in the array.
    When add is false, I must subtract a constant value to each element in the array.
    Assume this is very hot code, i.e. it is called very often. How expensive is the condition checking? I present the two scenarios.
    private void process(){
    for (int i=0;i<dimension1;i++)
    for (int ii=0;ii<dimension1;ii++)
      for (int iii=0;iii<dimension1;iii++)
        for (int iiii=0;iiii<dimension1;iiii++)
             if (add)
             matrix[i][ii][iii][...]  += constant;
             else
             matrix[i][ii][iii][...]  -= constant;
    private void process(){
      if (add)
    for (int i=0;i<dimension1;i++)
    for (int ii=0;ii<dimension1;ii++)
      for (int iii=0;iii<dimension1;iii++)
        for (int iiii=0;iiii<dimension1;iiii++)
             matrix[i][ii][iii][...]  += constant;
    else
    for (int i=0;i<dimension1;i++)
    for (int ii=0;ii<dimension1;ii++)
      for (int iii=0;iii<dimension1;iii++)
        for (int iiii=0;iiii<dimension1;iiii++)
           matrix[i][ii][iii][...]  -= constant;
    }Is the second scenario worth a significant performance boost? Without understanding how the compilers generates executable code, it seems that in the first case, n^d conditions are checked, whereas in the second, only 1. It is however, less elegant, but I am willing to do it for a significant improvement.

    erjoalgo wrote:
    I guess my real question is, will the compiler optimize the condition check out when it realizes the boolean value will not change through these iterations, and if it does not, is it worth doing that micro optimization?Almost certainly not; the main reason being that
    matrix[i][ii][iii][...]  +/-= constantis liable to take many times longer than the condition check, and you can't avoid it. That said, Mel's suggestion is probably the best.
    but I will follow amickr advice and not worry about it.Good idea. Saves you getting flamed with all the quotes about premature optimization.
    Winston

  • JAVA Performance data in EWA is missing.

    Hi SAP-experts,
    our EWA is missing the JAVA performance data.  In transaction 
    u201CSOLMAN_WORKCENTER->Root Cause Analysis->End-to-End-Analysis->JAVA-System-><One of our java-system>->Workload Analysis-><SID> - Applicaton Server Javau201D
    no data for E2E Metric Type Variable(multiple values) SERVLETS is available.  And in transaction
    SOLMAN_WORKCENTER->Root Cause Analysis->End-to-End-Analysis->JAVA-System-><One of our java-system>->Workload Analysis->Overviewu201D
    all KPIs are u201Cn/au201D.
    The transaction LISTCUBE (Infoprovider=0SMD_PE2H) shows no entries for selection :
    Metric Type: HTTP SESSIONS
    System ID: <SID of Java System>
    Calendar Day: <startday> to <endday>
    (Recommended by Dokument: End-to-End Diagnostics Trouble Shooting Guide missing data in service session from BI/CCDB)
    The Extractors E2E_JAVA_EXTRACTOR_* are running.
    Introscope Extractors are scheduled for the managed system Checked it in table E2E_ACTIVE_WLI.
    Records are loaded. Checked Table E2E_EFWK_STATUS.
    (Recommended by Dokument: End-to-End Diagnostics Trouble Shooting Guide missing data in service session from BI/CCDB)
    The spool of job E2E HKCONTROLLER shows this error:
    Target Infocube: 0SMD_PE2D
    Source Infocube: 0SMD_PE2H
    Destination    : NONE
    Aggregator     :
    E2E_HK_AGGREGATE
    HK: Calling SMD_HOUSEKEEPER at NONE
    HK: Error detected by SMD_HK_AGGREGATE
    HK: Status :     0
    HK: Message:
    RSAPO_CLOSE_TRANS_REQUEST failed
    HK: New Requests found:
    APO_R4NGX6OEQD7GGFVSO540DFAIRW
    APO_R4NGSA2CB8MO33L1833NBXTV9O
    Runtime [s]:           9
    In my opinion there is a problem with the data transfer in the infoproviders 0SMD_PE2D and 0SMD_PE2D. What further checks can I do and how can I resolve this problem?
    Best regards
    Willi Eimler

    last  part of the version data
    (IA64)[hp10202:root]/usr/sap/hostctrl/exe> saphostexec -status                             
    saphostexec running (pid = 20880)                                                          
    sapstartsrv running (pid = 20894)                                                          
    09:31:00 13.10.2011     LOG: Using PerfDir (DIR_PERF) = /usr/sap/tmp                       
    saposcol running (pid = 12780)                                                                               
    (IA64)[hp10202:root]/usr/sap/hostctrl/exe> saphostexec -version                            
    Component ********************                                 
    ./saphostexec: 720, patch 92, changelist 1256713, hpia64, opt (Jun 15 2011, 22:42:14)      
    ./sapcimc: 720, patch 92, changelist 1256713, hpia64, opt (Jun 15 2011, 22:42:14)          
    SAPHOSTAGENT information                                                                   
    kernel release                720                                                                               
    kernel make variant           720_REL                                                                               
    compiled on                   HP-UX B.11.23 U ia64 for hpia64                                                                               
    compiled for                  64 BIT                                                                               
    compilation mode              Non-Unicode                                                                               
    compile time                  Jun 15 2011 22:37:28                                                                               
    patch number                  68                                                                               
    latest change number          1256713                                                                               
    supported environment                                                                      
    operating system                                                                           
    HP-UX B.11

  • Flash/java remoting question

    Hi,
    i'm new to flash remoting and am finding using it with java
    quite troublesome. I've also found using the FileReference class
    troublesome if you use java. my question is can you somehow tie the
    remoting functionality to the FileReference.upload method
    fucntionality??
    thanks in advance

    I will use the program with photo detector to test
    the response time of the LCD screenWhy Java?I second that. With a test like that, you want to reduce the experiment down to a single variable, in this case the lcd response time. Using a java program to feed the monitor input introduces a second variable, the response time of the program. The java program's timer may not be exact, the components may not be repainted completely quickly enough, etc. If this is just for your own amusement, maybe that doesn't matter, but if you want your results to have any reliability, you'll need a more accurate and controllable input source.

  • BPM performance question

    Guys,
    I do understand that ccPBM is very resource hungry but what I was wondering is this:
    Once you use BPM, does an extra step decreases the performance significantly? Or does it just need slightly more resources?
    More specifically we have quite complex mapping in 2 BPM steps. Combining them would make the mapping less clear but would it worth doing so from the performance point of view?
    Your opinion is appreciated.
    Thanks a lot,
    Viktor Varga

    Hi,
    In SXMB_ADM you can set the time out higher for the sync processing.
    Go to Integration Processing in SXMB_ADM and add parameter SA_COMM CHECK_FOR_ASYNC_RESPONSE_TIMEOUT to 120 (seconds). You can also increase the number of parallel processes if you have more waiting now. SA_COMM CHECK_FOR_MAX_SYNC_CALLS from 20 to XX. All depends on your hardware but this helped me from the standard 60 seconds to go to may be 70 in some cases.
    Make sure that your calling system does not have a timeout below that you set in XI otherwise yours will go on and finish and your partner may end up sending it twice
    when you go for BPM the whole workflow
    has to come into action so for example
    when your mapping last < 1 sec without bpm
    if you do it in a BPM the transformation step
    can last 2 seconds + one second mapping...
    (that's just an example)
    so the workflow gives you many design possibilities
    (brigde, error handling) but it can
    slow down the process and if you have
    thousands of messages the preformance
    can be much worse than having the same without BPM
    see below links
    http://help.sap.com/bp_bpmv130/Documentation/Operation/TuningGuide.pdf
    http://help.sap.com/saphelp_nw04/helpdata/en/43/d92e428819da2ce10000000a1550b0/content.htm
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/xi/3.0/sap%20exchange%20infrastructure%20tuning%20guide%20xi%203.0.pdf
    BPM Performance tuning
    BPM Performance issue
    BPM performance question
    BPM performance- data aggregation persistance
    Regards
    Chilla..

  • Java Performance Pack

    What is Java Performance Pack?
    Where can I download it?

    http://java.sun.com/products/java-media/jmf/2.1.1/setup.html

  • Java Performance Hardware

    Hi,
    I have a theory that the java runtime is heavily dependent on a large cpu cache.
    Does anyone have any data that larger cpu caches give disproportionate performance improvements?
    I know that Java runs poorly with a 128K cache on X86. I moved up to a similar cpu to 256K and java performance jumped. The C++ code seemed to run about the same.
    1st CPU was Celeron 466 with 128 L2 Cache
    2nd CPU was PIII 600E with 256 L2 Cache.
    Same motherboard.
    I'm trying to decide if I need a 1MB cache versus 512K cache on similar CPU (AMD vs Intel).
    Comment appreciated.

    Well I think larger cache would just mean faster access to nearby memory data - and for highly optimised programs they always make sure that they take advantage of this feature.
    I reckon the reason why C++ code that you have tested might not have been significantly fast is due to the fact that it is not as optimised as the Java Interpreter, as the latter is a higher level language.
    Last but not the least, I think there are many other factors when considering a purchase of hardware - for instance its expected lifetime (my experience still suggests to me that AMD CPUs break down more easily than Intel ones)
    Hope this helps~
    Alex Lam S.L.

  • Which influence Java performance most -- processor speed, memory or cache

    Which influence Java performance under Windows most -- processor speed, memory or cache?
    I realize all three are importance. Adding memory is usually simple. But would you choose a slower P4 w/cache or a faster Celeron w/o cache. How much does 8KB of cache vs 32KB of cache effect Java.
    Thanks all!

    This is not strictly a Java issue - you are asking about the the realtive benefits to CPU bound programs of various CPU tradeoffs. There is no one right answer.
    More cache (level one and level two) is great, but the 'right' amount depends on the difference in memory access and bandwidth versus the ability of the CPU to digest data and code. If all things are equal (CPU speed, memory bandwidth, processor architecture), then more level one and level two cache is better. But I think there is not a great chance that more cache would make up for significant (>20%) difference in CPU clock rate (again with processor architecture and memory bandwidth held constant).
    Clock rates should not be used to compare processors of different designs. A 900MHz PA87xx is a lot faster (at some things) than a 1.6GHz P4. An AMD Athlon running at 1.5GHz gives a 2.0GHz P4 a good run for its money.
    The best bet would be to look for comparisions made against CPU bound benchmarks. www.spec.org's specJVM98 and specJBB2000 would be a great tool, but there isn't much existing data to compare. You could of course license and run the benchmarks yourself. You can also look to other benchmarks (look at the comparisons at www.tomshardware.com, etc.) to compare, there are plenty to choose from.

  • Xcontrol: performance question (again)

    Hello,
    I've got a little performance question regarding xcontrols. I observed rather high cpu-load when using xcontrols. To investigate it further, I built a minimal xcontrol (boolean type) which only writes the received boolean-value to a display-element in it's facade (see attached example). When I use this xcontrol in a test-vi and write to it with a rate of 1000 booleans / second, I get a cpu-load of about 10%. When I write directly to a boolean display element instead of the xcontrol,I have a load of 0 to 1 %. The funny thing is, when I emulate the xcontrol functionality with a subvi, a subpanel and a queue (see example), I only have 0 to 1% cpu-load, too.
    Is there a way to reduce the cpu-load when using xcontrols? 
    If there isn't and if this is not a problem with my installation but a known issue, I think this would be a potential point for NI to fix in a future update of LV.
    Regards,
    soranito
    Message Edited by soranito on 04-04-2010 08:16 PM
    Message Edited by soranito on 04-04-2010 08:18 PM
    Attachments:
    XControl_performance_test.zip ‏60 KB

    soranito wrote:
    Hello,
    I've got a little performance question regarding xcontrols. I observed rather high cpu-load when using xcontrols. To investigate it further, I built a minimal xcontrol (boolean type) which only writes the received boolean-value to a display-element in it's facade (see attached example). When I use this xcontrol in a test-vi and write to it with a rate of 1000 booleans / second, I get a cpu-load of about 10%. When I write directly to a boolean display element instead of the xcontrol,I have a load of 0 to 1 %. The funny thing is, when I emulate the xcontrol functionality with a subvi, a subpanel and a queue (see example), I only have 0 to 1% cpu-load, too.
    Okay, I think I understand question  now.  You want to know why an equivalent xcontrol boolean consumes 10x more CPU resource than the LV base package boolean?
    Okay, try opening the project I replied yesterday.  I don't have access to LV at my desk so let's try this. Open up your xcontrol facade.vi.  Notice how I separated up your data event into two events?  Go the data change vi event, when looping back the action, set the isDataChanged (part of the data change cluster) to FALSE.  While the data input (the one displayed on your facade.vi front panel), set that isDataChanged to TRUE.  This is will limit the number of times facade will be looping.  It will not drop your CPU down from 10% to 0% but it should drop a little, just enough to give you a short term solution.  If that doesn't work, just play around with the loopback statement.  I can't remember the exact method.
    Yeah, I agree xcontrol shouldn't be overconsuming system resource.  I think xcontrol is still in its primitive form and I'm not sure if NI is planning on investing more times to bug fix or even enhance it.  Imo, I don't think xcontrol is quite ready for primetime yet.   Just too many issues that need improvement.
    Message Edited by lavalava on 04-06-2010 03:34 PM

  • Can I post here(Acrobat Windows) Java Script questions here?

    Hello
    Can I post here(Acrobat Windows) Java Script questions here? If not, wht is the correct forum?
    THank you

    Back up and down to Acrobat Scripting. Bot Windows and MacIntosh Acrobat versions use the same JavaScript.
    If you are using LIVECYCLE DESIGNER use their forums. The JavaScript syntax and objects are different in LIVECYCLE DESIGNER!

  • Import: performance question

    Hi, what is the different between these statements for application in term of performance?
    import java.io.*;
    and
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    Which one is faster for execution?

    Neither. Search the forums or web for the countless answers to the same question.

  • Copying arrays, performance questions

    Hello there
    The JDK offers several ways to copy arrays so I ran some experiments to try and find out which would be the fastest.
    I was measuring the time it takes to copy large arrays of integers. I wrote a program that allocates arrays of various sizes, and copy them several times using different methods. Then I measured the time each method took using the NetBeans profiler and calculated the frequencies.
    Here are the results I obtained (click for full size):  http://i.share.pho.to/dc40172a_l.png
    (what I call in-place copy is just iterating through the array with a for loop and copying the values one by one)
    I generated a graph from those values:  http://i.share.pho.to/049e0f73_l.png
    A zoom on the interesting part: http://i.share.pho.to/a9e9a6a4_l.png
    According to these results, clone() becomes faster at some point (not sure why). I've re-ran these experiments a few times and it seems to always happen somewhere between 725 and 750.
    Now here are my questions:
    - Is what I did a valid and reliable way to test performances, or are my results completely irrelevant? And if it's not, what would be a smarter way to do this?
    - Will clone be faster than arraycopy past 750 items on any PC or will these results be influences by other factors?
    - Is there a way to write a method that would copy the array with optimal performances using clone and arraycopy, such that the cost of using it would be insignificant compared to systematically using one method over the other?
    - Any idea why clone() can become faster for bigger arrays? I know arraycopy is a native method, I didn't try to look into what it does exactly but I can't imagine it's doing anything more complicating than copying elements from one location in the memory to another... How can another method be faster than that?
    (just reminding I'm copying primitives, not objects)
    Thanks!
    Message was edited by: xStardust! Added links, mr forum decided to take away my images

    yeh, everyone thinks that at some point. it relies,
    however, on you being perfect and knowing everything
    in advance, which you aren't, and don't (no offence,
    the same applies to all of us!). time and time again,
    people do this up-front and discover that what they
    thought would be a bottleneck, isn't. plus,
    the JVM is much smarter at optimizing code than you
    think: trust it. the best way to get good performance
    out of your code is to write simple, straightforward
    good OO code. JVMs are at a point now where they can
    optimize java to outperform equivalent C/C++ code
    (no, really) but since they're written by human
    beings, who have real deadlines and targets, the
    optimizations that make it into a release are the
    most common ones. just write your application, and
    then see how it performs. trust me on this
    have a read of
    [url=http://java.sun.com/developer/technicalArticles/I
    nterviews/goetz_qa.html]this for more info anda chance to see where I plagiarized that post from :-)
    Thanks for that link you gave me :)
    Was usefull to read.
    About time and money of programming, that is not really an issue for me atm since i'm doing this project for a company, but through school (it's like working but not for money).
    Of course it should not last entirely long but I got time to figure out alot of things.
    For my next project I will try to focus some more on building first, optimizing performance later (if it can be done with a good margin, since it seems the biggest bottlenecks are not the code but things outside the code).
    @promethuuzz
    The idea was to put collection objects (an object that handles the orm objects initialized) in the request and pass them along to the jsp (this is all done through a customized mvc model).
    So I wanted to see if this method was performance heavy so I won't end up writing the entire app and finding out halve of it is very performance heavy :)

Maybe you are looking for