Rlim_fd_cur=  and  rlim_fd_max=

Hi,
Someone please tell me how to set these kernel parameters in solaris 11
set rlim_fd_cur=65536
set rlim_fd_max=65536
thanks...

Hi.
Same as at Solaris 10 etc.
http://docs.oracle.com/cd/E26502_01/html/E29022/chapter2-29.html#chapter2-32
http://docs.oracle.com/cd/E26502_01/html/E29022/chapter1-9.html#chapter1-10
Add required line to /etc/system
Regards.

Similar Messages

  • LMS 4.1 - Solaris 10 Filedescriptor-Limit reached Tomcat-Process

    Hi all,
    environment: Oracle/Sun HW T5140 with Sol10 u9
    last friday we had a HTTP 500 Error-Message trying to connect to web-interface of LMS 4.1.
    After some troublehooting (/opt/CSCOpx/MDC/tomcat/logs/stdout.log) we discovered tomcat-problems unable to open Sockets.
    WARNING: Exception executing accept
    java.net.SocketException: Too many open files
            at java.net.PlainSocketImpl.socketAccept(Native Method)
            at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:408)
            at java.net.ServerSocket.implAccept(ServerSocket.java:462)
            at java.net.ServerSocket.accept(ServerSocket.java:430)
            at org.apache.jk.common.ChannelSocket.accept(ChannelSocket.java:312)
            at org.apache.jk.common.ChannelSocket.acceptConnections(ChannelSocket.java:667)
            at org.apache.jk.common.ChannelSocket$SocketAcceptor.runIt(ChannelSocket.java:878)
            at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
            at java.lang.Thread.run(Thread.java:662)
    Seachring thru Sun-Tuning docs I found following kernel-parameters for Filedescriptor tuning
    rlim_fd_cur and rlim_fd_max
    Settings on un-tuned Solaris 10 system
    </proc/5142/fd>#               echo rlim_fd_max/D | mdb -k
    rlim_fd_max:
    rlim_fd_max:    65536          
    </proc/5142/fd>#               echo rlim_fd_cur/D | mdb -k
    rlim_fd_cur:
    rlim_fd_cur:    256            
    With setting parameter rlim_fd_cur up to 1024 in /etc/systems I tried to tune Tomcat behavior.
    Are there any known but unfortunately not documented Best-Practise kernel-parameter settings for CiscoWorks LMS 4.1
    running on Solaris 10 SPARC-Systems?
    Thanks for any feedback
    Lothar

    I have had this 3 times with LMS 3.2 installed on solaris 9.
    I am wondering if you DCRDevicePoll service is still running correctly? This is the process that checks for device reachability (ICMP and/or SNMP) of the DCR devices. I found that this process is hanging from time to time and assume that it is interfering with some other process (I think IC polling/collection or Config polling/collecion).
    I was unable to get the poll job running again without stop, delete and recreate it.
    Have you observed simmilar issues with the poll job while the "file descriptor" issue was occuring?
    btw. ... I doubt that adjusting these parameter will prevent the problem...

  • Too many files

    I'm pretty new to the Solaris admin gig, so please bear with me...
    I am running into errors related to file descriptors. The logs are showing messages stating that there are "too many open file" to do whatever process the system is trying to do. I understand how to change the file limits by setting the rlim_fd_cur and rlim_fd_max variables in /etc/system (at least I think I do). However, I'm wondering how I can monitor the number of fd's per user or process so I can see exactly which process(es) is using them all up. Is this possible? If so, I'd appreciate any tips or tricks anyone can give me.
    Thank You!

    You can use "truss" to monitor per process fd's. Read up on it / google around to get
    the correct args etc etc
    Also "ulimit" to set fd's and printout current fd settting. Do a 'man' on it for more info
    Patrick/

  • WLS 5.1 hangs due to many sockets in CLOSE_WAIT state

    Hi,
    we are having some serious problems with Weblogic Server 5.1 (SP 6) with
    several of our customer installations (Solaris 5.8 and HP UX). The problem
    relates to the WLS http server not dealing with socket connections in
    CLOSE_WAIT state correctly. We have observered that these can be caused by
    Netscape browsers when the end user clicks on the reload button. This causes
    the socket connection to be placed in CLOSE_WAIT state, it stays like this
    for ever and eventually when there are many sockets in this state WLS runs
    out of file descriptors and hangs. We have tried using WLS Apache plugin but
    Apache merely passes the CLOSE_WAIT's onto WLS web server. Any help
    appreciated on this one,.....
    regards Donal.

    The problem is that your file descriptor table is filling up with sockets in the
    CLOSE_WAIT state so there is no more room to put new file descriptors. Any
    machine that speaks HTTP is subject to this so you need to apply these changes
    both to the web server machine(s) and the application server machine(s).
    The way to handle this on Solaris is to decrease the close wait interval:
    ndd -set /dev/tcp tcp_close_wait_interval 60000 (Solaris 2.6 and below)
    ndd -set /dev/tcp tcp_time_wait_interval 60000 (Solaris 2.7 and above)
    (NOTE: It is recommended that you not go below 60 seconds for this, as per
    Adrian Cockroft of SUN).
    and increase the size of the file descriptor table by adding the following in
    /etc/system:
    rlim_fd_cur 8192
    rlim_fd_max 8192
    (NOTE: The close wait interval can also be set in /etc/system, though I don't
    remember the name of the parameter off the top of my head.)
    Also, make sure that you change the startWebLogic.sh script to grab more file
    descriptors with ulimit (or simply remove the ulimit section of the script)...
    Hope this helps,
    Robert
    Donal Mc Ateer wrote:
    We have done this. We have made the following 'tweaks' to the Solaris
    installation
    ndd -set /dev/tcp tcp_keepalive_interval 300000
    ndd -set /dev/tcp tcp_ip_abort_interval 2000
    ndd -set /dev/tcp tcp_rexmit_interval_max 10000
    ndd -set /dev/tcp tcp_fin_wait_2_flush_interval 67500
    ndd -set /dev/tcp tcp_time_wait_interval 30000
    is there anything else we can do? Is there any way of influencing the WLS
    http server handling of these CLOSE_WAIT sockets? Is this being addressed in
    WLS 6.0?
    -Donal.
    "shivu" <[email protected]> wrote in message
    news:[email protected]...
    try tuning the tcp parameters at solaris level.
    (i think tcp_conn_wait)
    "Donal Mc Ateer" <[email protected]> wrote:
    Hi,
    we are having some serious problems with Weblogic Server 5.1 (SP 6) with
    several of our customer installations (Solaris 5.8 and HP UX). The
    problem
    relates to the WLS http server not dealing with socket connections in
    CLOSE_WAIT state correctly. We have observered that these can be causedby
    Netscape browsers when the end user clicks on the reload button. Thiscauses
    the socket connection to be placed in CLOSE_WAIT state, it stays likethis
    for ever and eventually when there are many sockets in this state WLSruns
    out of file descriptors and hangs. We have tried using WLS Apache pluginbut
    Apache merely passes the CLOSE_WAIT's onto WLS web server. Any help
    appreciated on this one,.....
    regards Donal.

  • Configure rlim_fd_max and rlim_fd_cur

    Hi All,
    I have few knowledge of solaris zones configuration, does anyone know how can i "configure" the kernel parameters rlim_fd_max and rlim_fd_cur for a zone, or do something similar ? Is this possible?
    I have found the something that looks like this but i am not sure it is what i am looking for ( process.max-file-descriptor ).
    Thanks in advance,
    Andrei

    andrei.dumitru wrote:
    Hi All,
    I have few knowledge of solaris zones configuration, does anyone know how can i "configure" the kernel parameters rlim_fd_max and rlim_fd_cur for a zone, or do something similar ? Is this possible?
    I have found the something that looks like this but i am not sure it is what i am looking for ( process.max-file-descriptor ).process.max-file-descriptor is what you're looking for. You set it in /etc/project instead of /etc/system.
    See the docs on Solaris Virtualization or Solaris Containers for /etc/projects examples (Chapter 6).
    You're going to need to read up on Solaris Projects.
    alan

  • Rlim_fd_max Kernel Parameter on Solaris 9

    I am trying to install Oracle Application Server 10g Release 2 on Solaris 9. The installation errors out on the "Select Configuration Options" screen with the following error:
    "Oracle Application Server 10g Web Cache requires the Kernel Parameter rlim_fd_max to be set to a value of 65536 or higher. Please set rlim_fd_max to 65536 or higher, reboot the machine and restart the installation".
    I checked the value of the set rlim_fd_max Kernel Parameter prior to starting the install and it is set to 65536. Does anyone know why I'm getting this error? Thanks in advance!

    I was able to get an answer by opening a SR with Metalink. The problem was that even though the rlim_fd_max default on Solaris 9 is 65536, it must be in the /etc/system file. Must be the installer looks at the file to determine that it is set correctly. So, adding set rlim_fd_max=65536 and set rlim_fd_cur=1024 to the /etc/system file fixed the problem.

  • Solaris Kernel and TCP/IP Tuning Parameters (Continued)

    This page describes some configuration optimizations for Solaris hosts running ATG Page Serving instances (application servers) that will increase server efficiency.
    Note that these changes are specific to Solaris systems running ATG application servers (+page serving+ instances). Do not use these on a web server or database server. Those systems require entirely different settings.
    h3. Solaris 10 Kernel
    Adjust /etc/system (parameters below) and reboot the system.
    set rlim_fd_cur=4096
    set rlim_fd_max=4096
    set tcp:tcp_conn_hash_size=32768
    set shmsys:shminfo_shmmax=4294967295
    set autoup=900
    set tune_t_fsflushr=1h4. Set limits on file descriptors
    {color:blue}set rlim_fd_max = 4096{color}
    {color:blue}set rlim_fd_cur = 4096{color}
    Raise the file-descriptor limits to a maximum of 4096. Note that this tuning option was not mentioned in the "Sun Performance And Tuning" book.
    [http://download.oracle.com/docs/cd/E19082-01/819-2724/chapter2-32/index.html]
    h4. Increase the connection hash table size
    {color:blue}set tcp:tcp_conn_hash_size=8192{color}
    Increase the connection hash table size to make look-up's more efficient. The connection hash table size can be set only once, at boot time.
    [http://download.oracle.com/docs/cd/E19455-01/816-0607/chapter4-63/index.html]
    h4. Increase maximum shared memory segment size
    {color:blue}set shmsys:shminfo_shmmax=4294967295{color}
    Increase the maximum size of a system V shared memory segment that can be created from roughly 8MB to 4GB.
    This provides an adequate ceiling; it does not imply that shared memory segments of this size will be created.
    [http://download.oracle.com/docs/cd/E19683-01/816-7137/chapter2-74/index.html]
    h4. Increase memory allocated for dirty pages
    {color:blue}set autoup=900{color}
    Increase the amount of memory examined for dirty pages in each invocation and frequency of file system synchronizing operations.
    The value of autoup is also used to control whether a buffer is written out from the free list. Buffers marked with the B_DELWRI flag (which identifies file content pages that have changed) are written out whenever the buffer has been on the list for longer than autoup seconds. Increasing the value of autoup keeps the buffers in memory for a longer time.
    [http://download.oracle.com/docs/cd/E19082-01/819-2724/chapter2-16/index.html]
    h4. Specify the time between fsflush invocations
    Specifies the number of seconds between fsflush invocations.
    {color:blue}set tune_t_fsflushr=1{color}
    [http://download.oracle.com/docs/cd/E19082-01/819-2724/chapter2-105/index.html]
    Again, note that after adjusting any of the preceding kernel parameters you will need to reboot the Solaris server.
    h3. TCP
    ndd -set /dev/tcp tcp_time_wait_interval 60000
    ndd -set /dev/tcp tcp_conn_req_max_q 16384
    ndd -set /dev/tcp tcp_conn_req_max_q0 16384
    ndd -set /dev/tcp tcp_ip_abort_interval 60000
    ndd -set /dev/tcp tcp_keepalive_interval 7200000
    ndd -set /dev/tcp tcp_rexmit_interval_initial 4000
    ndd -set /dev/tcp tcp_rexmit_interval_max 10000
    ndd -set /dev/tcp tcp_rexmit_interval_min 3000
    ndd -set /dev/tcp tcp_smallest_anon_port 32768
    ndd -set /dev/tcp tcp_xmit_hiwat 131072
    ndd -set /dev/tcp tcp_recv_hiwat 131072
    ndd -set /dev/tcp tcp_naglim_def 1h4. Tuning the Time Wait Interval and TCP Connection Hash Table Size
    {color:blue}/usr/sbin/ndd -set /dev/tcp tcp_time_wait_interval 60000{color}
    The tcp_time_wait_interval is how long a connection stays in the TIME_WAIT state after it has been closed (default value 240000 ms or 4 minutes). With the default setting, this socket will remain for 4 minutes after you have closed the FTP connection. This is normal operating behavior. It is done to ensure that any slow packets on the network will arrive before the socket is completely shutdown. As a result, a future program that uses the same socket number won't get confused upon receipt of packets that were intended for the previous program.
    On a busy Web server a large backlog of connections waiting to close could build up and the kernel can become inefficient in locating an available TCP data structure. Therefore it is recommended to change this value to 60000 ms or 1 minute.
    h4. Tuning the maximum number of requests per IP address per port
    {color:blue}ndd -set /dev/tcp tcp_conn_req_max_q 16384{color}
    {color:blue}ndd -set /dev/tcp tcp_conn_req_max_q0 16384{color}
    The {color:blue}tcp_conn_req_max_q{color} and {color:blue}tcp_conn_req_max_q0{color} parameters are associated with the maximum number of requests that can be accepted per IP address per port. tcp_conn_req_max_q is the maximum number of incoming connections that can be accepted on a port. tcp_conn_req_max_q0 is the maximum number of “half-open” TCP connections that can exist for a port. The parameters are separated in order to allow the administrator to have a mechanism to block SYN segment denial of service attacks on Solaris.
    The default values are be too low for a non-trivial web server, messaging server or directory server installation or any server that expects more than 128 concurrent accepts or 4096 concurrent half-opens. Since the ATG application servers are behind a DMZ firewall, we needn't starve these values to ensure against DOS attack.
    h4. Tuning the total retransmission timeout value
    {color:blue}ndd -set /dev/tcp tcp_ip_abort_interval 60000{color}
    {color:blue}tcp_ip_abort_interval{color} specifies the default total retransmission timeout value for a TCP connection. For a given TCP connection, if TCP has been retransmitting for tcp_ip_abort_interval period of time and it has not received any acknowledgment from the other endpoint during this period, TCP closes this connection.
    h4. Tuning the Keep Alive interval value
    {color:blue}ndd -set /dev/tcp tcp_keepalive_interval 7200000{color}
    {color:blue}tcp_keepalive_interval{color} sets a probe interval that is first sent out after a TCP connection is idle on a system-wide basis.
    If SO_KEEPALIVE is enabled for a socket, the first keep-alive probe is sent out after a TCP connection is idle for two hours, the default value of the {color:blue}tcp_keepalive_interval{color} parameter. If the peer does not respond to the probe after eight minutes, the TCP connection is aborted.
    The {color:blue}tcp_rexmit_interval_*{color} values set the initial, minimum, and maximum retransmission timeout (RTO) values for a TCP connections, in milliseconds.
    h4. Tuning the TCP Window Size
    {color:blue}/usr/sbin/ndd -set /dev/tcp tcp_xmit_hiwat 65535{color}
    {color:blue}/usr/sbin/ndd -set /dev/tcp tcp_recv_hiwat 65535{color}
    Setting these two parameters controls the transmit buffer and receive window. We are tuning the kernel to set each window to 65535 bytes. If you set it to 65536 bytes (64K bytes) or more with Solaris 2.6, you trigger the TCP window scale option (RFC1323).
    h4. Tuning TCP Slow Start
    {color:blue}/usr/sinb/ndd -set /dev/tcp tcp_slow_start_initial 4{color}
    tcp_slow_start_initial is the number of packets initially sent until acknowledgment, the congestion window limit.
    h4. Tuning the default bytes to buffer
    {color:blue}ndd -set /dev/tcp tcp_naglim_def 1{color}
    {color:blue}tcp_naglim_def{color} is the default number of bytes to buffer. Each connection has its own copy of this value, which is set to the minimum of the MSS for the connection and the default value. When the application sets the TCP_NODELAY socket option, it changes the connection's copy of this value to 1. The idea behind this algorithm is to reduce the number of small packets transmitted across the wire by introducing a short (100ms) delay for packets smaller than some minimum.
    Changing the value of tcp_naglim_def to 1 will have the same effect (on connections established after the change) as if each application set the TCP_NODELAY option.
    {note}
    The current value of any of the TCP parameters can be displayed with the command ndd get. So to retrieve the current setting of the {color:blue}tcp_naglim_def parameter{color}, simply execute the command:\\
    {color:blue}ndd -get /dev/tcp tcp_naglim_def{color}
    {note}
    h3. References
    Solaris Tunable Parameters Reference Manual
    [http://download.oracle.com/docs/cd/E19455-01/816-0607/index.html]
    WebLogic Server Performance and Tuning
    [http://download.oracle.com/docs/cd/E11035_01/wls100/perform/OSTuning.html]

    For example,
    Socket.setSoTimeout() sets SO_TIMEOUT option and I
    want to what TCP parameter this option corresponds in
    the underlying TCP connection.This doesn't correspond to anything in the connection, it is an attribute of the API.
    The same questions
    arises fro other options from SocketOptions class.setTcpNoDelay() controls the Nagle algorithm. set{Send,Receive}BufferSize() controls the local socket buffers.
    Most of this is quite adequately described in the javadoc actually.

  • Find and send solution urgent

    I have encountered the following exception when I run the
    following program using runtime.exec() in solaris. If you have
    some idea about it, please let me know.
    Thanks.
    ========= Exception Information ======
    java.io.IOException: Too many open files
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.forkAndExec(Compiled Code)
    at java.lang.UNIXProcess.<init>(Compiled Code)
    at java.lang.Runtime.execInternal(Native Method)
    at java.lang.Runtime.execInternal(Compiled Code)
    at java.lang.Runtime.exec(Compiled Code)
    at java.lang.Runtime.exec(Compiled Code)
    at java.lang.Runtime.exec(Compiled Code)
    at TestPro.run(Compiled Code)
    at TestPro.main(TestPro.java:29)
    ========= My Program ============
    I wrote the program in JSP on UNIX platform using tomcat server.
    Runtime.getRuntime.exec("sh coc.sh "+filename+" "+fileexec);
    it is successful execute and create the executefile of the filename(Example : filename.c)
    how to execute the fileexec file.
    i can use again Runtime.getRuntime.exec("fileexec");
    it is give above errors.
    please find out solution and send me immediatly.
    mail to : [email protected]

    It looks like Solaris cannot assign you a new file descriptor since all available descriptors are already in use. We have experienced the same problem under Solaris 7. A possible solution is to adjust the maximum number of open files in the /etc/system configuration file. Search for the following entry (or add it)
    * JVM often reports errors about too many open files
    set rlim_fd_cur=1024
    set rlim_fd_max=4096
    I think you will have to reboot the machine after changing the file.

  • Set rlim_fd_cur=8192 for Solaris 10 Zone?

    Hi!
    I would like to install SAP Solution Manager 7.0 on Solaris 10 Zone (Sparc 64 Bit).
    Unfortunately I could find the file etc/system. Instead I added the project file acording to SAP note 724713.
    When I run SAP prerequisite Checker SAPINST tells me that the following will be missed:
    set rlim_fd_cur=8192 in etc/system.
    Question:
    Do I need to add the file etc/system and add them the following commando:
    set rlim_fd_cur=8192?
    Or does this commando not apply for Solaris 10?
    Thank you very much!
    regards
    Thom

    > In solaris 9 and below, it was needed to add the parameter in /etc/system. With solaris 10 no need.
    This is not completely true.
    The number of maximum open files must be set in the global zone, otherwise you will run into problems once the total number of processes in all zones will be > 1024 - hence you need to also set this in Solaris 10.
    A zone has no /etc/system thus that error can be ignored.
    Markus

  • Monitor the number of emails and email traffic?

    is there a way - an application or widget - that allows you to monitor the amount (number of in and out) for my email?

    I called Sun on this one, and found that everything is included under rlim_fd_max, unix sockets, std file descriptors, pipes, everything. At least I now know what to monitor with LSOF.
    Dave

  • Ulimit(stack) and ulimit(nofiles) needs to be changed.

    root@iibtreasury2 # ulimit -a
    time(seconds) unlimited
    file(blocks) unlimited
    data(kbytes) unlimited
    stack(kbytes) 8192
    coredump(blocks) unlimited
    nofiles(descriptors) 1024
    memory(kbytes) unlimited
    root@iibtreasury2 #
    And
    root@iibtreasury1 # ulimit -Ha
    core file size (blocks, -c) unlimited
    data seg size (kbytes, -d) unlimited
    file size (blocks, -f) unlimited
    open files (-n) 65536
    pipe size (512 bytes, -p) 10
    stack size (kbytes, -s) unlimited
    cpu time (seconds, -t) unlimited
    max user processes (-u) 16384
    virtual memory (kbytes, -v) unlimited
    root@iibtreasury1 #
    how to:-
    1)Increase the ulimit(STACK) to a minimum of 32768
    2)Increase the ulimit(NOFILES) to a minimum of 4096
    permanently.
    these are entries in /etc/system
    set noexec_user_stack=1
    set max_nprocs = 30000
    set maxuprc = 16384
    set rlim_fd_cur=1024
    set shmsys:shminfo_shmmax=12884901888

    well, after hours of searching around on the web and just after posting my question I now finally found this:
    http://www.sapgeek.net/2010/10/sap-j2ee-engine-db-connection/
    Using the configtool.bat (logged in with windows account <SID>adm and startet it from E:\usr\sap\<SID>\Jxx\j2ee\configtool) I was able to edit the connection string accordingly.
    Now j2ee starts up properly.
    Regards
    Renaud

  • A problem with Threads and loops.

    Hi, I have some code that needs to be constantly running, like while(true)
          //code here
    }However, the code just checks to see if the user has input anything (and then if the user has, it goes to do some other stuff) so I don't need it constantly running and hogging up 98% of the CPU. So I made my class (which has the method that needs to be looped, call it ClassA) implement Runnable. Then I just added the method which needed to be looped into the public void run()
    I have another class which creates an instance of the above class (call it ClassB), and the main(String[] args) is in there.
    public static void main(String[] args)
              ClassA test = new ClassA();
              Thread thread = new Thread(test.getInstanceOfClassA());
              thread.start();
              while(true)
                           //I do not know what to put here
                   try
                        thread.sleep(100);
                   catch(InterruptedException iex)
         }However, the thread only calls run() once,(duh...) but I can't think of away to get it to run - sleep - run -sleep forever. Can someone help me?

    Hi, I have some code that needs to be constantly
    running, like while(true)
    //code here
    }However, the code just checks to see if the user has
    input anything (and then if the user has, it goes to
    do some other stuff) so I don't need it constantly
    running and hogging up 98% of the CPU. Where does the user input come from. Are you reading from an InputStream? If so, then your loop will be blocked anyway when reading from the InputStream until data is available. During that time, the loop will not consume processor cycles.
    public static void main(String[] args)
              ClassA test = new ClassA();
    Thread thread = new Thread(test.getInstanceOfClassA());I have never seen this idiom. If ClassA instanceof Runnable, you simply write new Thread(test).
              thread.start();
              while(true)
    //I do not know what to put
    do not know what to put here
                   try
                        thread.sleep(100);
                   catch(InterruptedException iex)
         }However, the thread only calls run() once,(duh...)Yeah, why would you want to call it more than once given that you have an infinite loop in ClassA.run()?
    Harald.
    Java Text Crunching: http://www.ebi.ac.uk/Rebholz-srv/whatizit/software

  • A problem with Threads and MMapi

    I am tring to execute a class based on Game canvas.
    The problem begin when I try to Play both a MIDI tone and to run an infinit Thread loop.
    The MIDI tone "Stammers".
    How to over come the problem?
    Thanks in advance
    Kobi
    See Code example below:
    import java.io.IOException;
    import java.io.InputStream;
    import javax.microedition.lcdui.Graphics;
    import javax.microedition.lcdui.Image;
    import javax.microedition.lcdui.game.GameCanvas;
    import javax.microedition.media.Manager;
    import javax.microedition.media.MediaException;
    import javax.microedition.media.Player;
    public class MainScreenCanvas extends GameCanvas implements Runnable {
         private MainMIDlet parent;
         private boolean mTrucking = false;
         Image imgBackgound = null;
         int imgBackgoundX = 0, imgBackgoundY = 0;
         Player player;
         public MainScreenCanvas(MainMIDlet parent)
              super(true);
              this.parent = parent;
              try
                   imgBackgound = Image.createImage("/images/area03_bkg0.png");
                   imgBackgoundX = this.getWidth() - imgBackgound.getWidth();
                   imgBackgoundY = this.getHeight() - imgBackgound.getHeight();
              catch(Exception e)
                   System.out.println(e.getMessage());
          * starts thread
         public void start()
              mTrucking = true;
              Thread t = new Thread(this);
              t.start();
          * stops thread
         public void stop()
              mTrucking = false;
         public void play()
              try
                   InputStream is = getClass().getResourceAsStream("/sounds/scale.mid");
                   player = Manager.createPlayer(is, "audio/midi");
                   player.setLoopCount(-1);
                   player.prefetch();
                   player.start();
              catch(Exception e)
                   System.out.println(e.getMessage());
         public void run()
              Graphics g = getGraphics();
              play();
              while (true)
                   tick();
                   input();
                   render(g);
          * responsible for object movements
         private void tick()
          * response to key input
         private void input()
              int keyStates = getKeyStates();
              if ((keyStates & LEFT_PRESSED) != 0)
                   imgBackgoundX++;
                   if (imgBackgoundX > 0)
                        imgBackgoundX = 0;
              if ((keyStates & RIGHT_PRESSED) != 0)
                   imgBackgoundX--;
                   if (imgBackgoundX < this.getWidth() - imgBackgound.getWidth())
                        imgBackgoundX = this.getWidth() - imgBackgound.getWidth();
          * Responsible for the drawing
          * @param g
         private void render(Graphics g)
              g.drawImage(imgBackgound, imgBackgoundX, imgBackgoundY, Graphics.TOP | Graphics.LEFT);
              this.flushGraphics();
    }

    You can also try to provide a greater Priority to your player thread so that it gains the CPU time when ever it needs it and don't harm the playback.
    However a loop in a Thread and that to an infinite loop is one kind of very bad programming, 'cuz the loop eats up most of your CPU time which in turn adds up more delays of the execution of other tasks (just as in your case it is the playback). By witting codes bit efficiently and planning out the architectural execution flow of the app before start writing the code helps solve these kind of issues.
    You can go through [this simple tutorial|http://oreilly.com/catalog/expjava/excerpt/index.html] about Basics of Java and Threads to know more about threads.
    Regds,
    SD
    N.B. And yes there are more articles and tutorials available but much of them targets the Java SE / EE, but if you want to read them here is [another great one straight from SUN|http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html] .
    Edited by: find_suvro@SDN on 7 Nov, 2008 12:00 PM

  • Problem with Threads and a static variable

    I have a problem with the code below. I am yet to make sure that I understand the problem. Correct me if I am wrong please.
    Code functionality:
    A timer calls SetState every second. It sets the state and sets boolean variable "changed" to true. Then notifies a main process thread to check if the state changed to send a message.
    The problem as far I understand is:
    Assume the timer Thread calls SetState twice before the main process Thread runs. As a result, "changed" is set to true twice. However, since the main process is blocked twice during the two calls to SetState, when it runs it would have the two SetState timer threads blocked on its synchronized body. It will pass the first one, send the message and set "changed" to false since it was true. Now, it will pass the second thread, but here is the problem, "changed" is already set to false. As a result, it won't send the message even though it is supposed to.
    Would you please let me know if my understanding is correct? If so, what would you propose to resolve the problem? Should I call wait some other or should I notify in a different way?
    Thanks,
    B.D.
    Code:
    private static volatile boolean bChanged = false;
    private static Thread objMainProcess;
       protected static void Init(){
            objMainProcess = new Thread() {
                public void run() {
                    while( objMainProcess == Thread.currentThread() ) {
                       GetState();
            objMainProcess.setDaemon( true );
            objMainProcess.start();
        public static void initStatusTimer(){
            if(objTimer == null)
                 objTimer = new javax.swing.Timer( 1000, new java.awt.event.ActionListener(){
                    public void actionPerformed( java.awt.event.ActionEvent evt){
                              SetState();
        private static void SetState(){
            if( objMainProcess == null ) return;
            synchronized( objMainProcess ) {
                bChanged = true;
                try{
                    objMainProcess.notify();
                }catch( IllegalMonitorStateException e ) {}
        private static boolean GetState() {
            if( objMainProcess == null ) return false;
            synchronized( objMainProcess ) {
                if( bChanged) {
                    SendMessage();
                    bChanged = false;
                    return true;
                try {
                    objMainProcess.wait();
                }catch( InterruptedException e ) {}
                return false;
        }

    Thanks DrClap for your reply. Everything you said is right. It is not easy to make them alternate since SetState() could be called from different places where the state could be anything else but a status message. Like a GREETING message for example. It is a handshaking message but not a status message.
    Again as you said, There is a reason I can't call sendMessage() inside setState().
    The only way I was able to do it is by having a counter of the number of notifies that have been called. Every time notify() is called a counter is incremented. Now instead of just checking if "changed" flag is true, I also check if notify counter is greater than zero. If both true, I send the message. If "changed" flag is false, I check again if the notify counter is greater than zero, I send the message. This way it works, but it is kind of a patch than a good design fix. I am yet to find a good solution.
    Thanks,
    B.D.

  • Problem with Threads and "plase wait..."-Window

    Hi everyone,
    I have a problem that I'm not able to solve in any way... I have a time-consuming task (a file decryption) which I execute in a separate thread; I've used the SwingWorker class, like suggested by sun-tutorial, and it works right. The problem is that I have to wait that the decryption have finished before continuing with program-execution. Therefore I would like to display a "please wait"-window while the task runs. I've tryed all the possible ways I know but the problem is always the same: the waitWindow is displayed empty, the bounds are painted but the contents no; it's only painted when the decrypt-task has finished. Please help me, I have no more resources....
    decrypt-file code:
    public class DecryptFile {
      private String cryptedFileNameAndPath;
      private ByteArrayInputStream resultStream = null;
      // need for progress
      private int lengthOfTask;
      private int current = -1;
      private String statMessage;
      public DecryptFile(String encZipFileNameAndPath) {
        cryptedFileNameAndPath = encZipFileNameAndPath;
        //Compute length of task...
        // 0 for indeterminate
        lengthOfTask = 0;
      public ByteArrayInputStream getDecryptedInputStream() {
        return this.resultStream;
       * Called from ProgressBarDemo to start the task.
      public void go() {
        current = -1;
        final SwingWorker worker = new SwingWorker() {
          public Object construct() {
            return new ActualTask();
        worker.start();
       * Called from ProgressBarDemo to find out how much work needs
       * to be done.
      public int getLengthOfTask() {
        return lengthOfTask;
       * Called from ProgressBarDemo to find out how much has been done.
      public int getCurrent() {
        return current;
      public void stop() {
        current = lengthOfTask;
       * Called from ProgressBarDemo to find out if the task has completed.
      public boolean done() {
        if (current >= lengthOfTask)
          return true;
        else
          return false;
      public String getMessage() {
        return statMessage;
       * The actual long running task.  This runs in a SwingWorker thread.
      class ActualTask {
        ActualTask () {
          current = -1;
          statMessage = "";
          resultStream = AIUtil.getInputStreamFromEncZip(cryptedFileNameAndPath); //here the decryption happens
          current = 0;
          statMessage = "";
      }The code that calls decryption and displays waitWindow
          final WaitSplash wS = new WaitSplash("Please wait...");
          final DecryptFile cryptedTemplate = new DecryptFile (this.templateFile);
          cryptedTemplate.go();
          while (! cryptedTemplate.done()) {
            try {
              wait();
            } catch (Exception e) { }
          this.templateInputStream = cryptedTemplate.getDecryptedInputStream();
          wS.close();Thanks, thanks, thanks in advance!
    Edoardo

    Maybe you can try setting the priority of the long-running thread to be lower? so that the UI will be more responsive...

Maybe you are looking for

  • Crystal Reports 10 - Export to TEXT with Delimited Space Format

    Hello, I am new to Crystal reports, sorry if this is a really basic question.  I am trying to create a report which I can export to a TXT file.  The TXT file format will be delimted space (size 500 characters).  I would like to know how I can use Cry

  • HT1692 Is my iPad one not syncing now because it's no longer supported for updates?

    Help my iPad 1 is no longer syncing wi my calendar and for some strange reason my iPhone 5 will get duplicate posts. My beloved syncing messages are all over the shop. I am running lion on my macs and latest software when I can I just am all of sudde

  • AT NEW command for two fields

    Dear All, How to use AT NEW command in internal table for two fields. Warm Regards, N.Jain

  • Preserve spaces in File Content Conversion

    Dears colleagues,   we have a problem with the File Content Conversion in SAP PI 7.1   We send an IDOC from SAP to PI and a file to an external system. For example we have:   IDOC Z,   Segment S1 with fields   F1   F2 Segment S2 with fields F3 F4 the

  • Table (css) text align in ff

    does anybody know of an issue where setting a table class with text-align attributes won't center the text of the table in firefox? I can force it to center by adjusting the align attribute in the <table> tag, but i have a several tables that i would