Problem in thread creation

Hello Frnds,
i am learning j2me..i am facing some problem in simple thread initilization..
the code is
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
import javax.microedition.io.*;
class Process implements Runnable
private FileConnection MIDlet1;
private Display display;
public Process()
MIDlet1=MIDlet2;
public void run()
try
transmit ();
catch (Exception error)
System.err.println(error.toString());
public void start()
Thread thread = new Thread(this);
try
thread.start();
catch(Exception e)
// System.out.println(e);
private void transmit() throws IOException
try
OutputConnection connection = (OutputConnection)Connector.open("file://c:/myfile.txt;append=true", Connector.WRITE );
OutputStream out = connection.openOutputStream();
PrintStream output = new PrintStream( out );
output.println( "This is a test." );
out.close();
connection.close();
catch( ConnectionNotFoundException error )
catch( IOException error )
Alert alert = new Alert("Error", error.toString(), null, null);
alert.setTimeout(Alert.FOREVER);
alert.setType(AlertType.ERROR);
display.setCurrent(alert);
catch(Exception error)
public class FileConnection extends MIDlet implements CommandListener
private Command exit, start;
private Display display;
private Form form;
public FileConnection ()
display = Display.getDisplay(this);
exit = new Command("Exit", Command.EXIT, 1);
start = new Command("Start", Command.EXIT, 1);
form = new Form("Write To File");
form.addCommand(exit);
form.addCommand(start);
form.setCommandListener(this);
public void startApp() throws MIDletStateChangeException
display.setCurrent(form);
public void pauseApp()
public void destroyApp(boolean unconditional)
public void commandAction(Command command, Displayable displayable)
if (command == exit)
destroyApp(false);
notifyDestroyed();
else if (command == start)
process.start();
}//middlet ends here
this code is givin null pinter exception and it does not initialize proocess class..vat is error..plz let me know

oh ..there was some problem..sending it again
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
import javax.microedition.io.*;
public class FileConnection extends MIDlet implements CommandListener
private Command exit, start;
private Display display;
private Form form;
public FileConnection ()
display = Display.getDisplay(this);
exit = new Command("Exit", Command.EXIT, 1);
start = new Command("Start", Command.EXIT, 1);
form = new Form("Write To File");
form.addCommand(exit);
form.addCommand(start);
form.setCommandListener(this);
public void startApp() throws MIDletStateChangeException
display.setCurrent(form);
public void pauseApp()
public void destroyApp(boolean unconditional)
public void commandAction(Command command, Displayable displayable)
if (command == exit)
destroyApp(false);
notifyDestroyed();
else if (command == start)
Process process=new Process(this);
process.start();
}//middlet ends here
class Process implements Runnable
private FileConnection MIDlet;
private Display display;
public Process(FileConnection MIDlet)
this.MIDlet=MIDlet;
public void run()
try
OutputConnection connection = (OutputConnection)
Connector.open("file://D:/Programs/Hello.txt", Connector.WRITE );
OutputStream out = connection.openOutputStream();
PrintStream output = new PrintStream( out );
output.println( "This is a test." );
out.close();
connection.close();
Alert alert = new Alert("Completed", "Data Written", null, null);
alert.setTimeout(Alert.FOREVER);
alert.setType(AlertType.ERROR);
display.setCurrent(alert);
catch( ConnectionNotFoundException error )
Alert alert = new Alert("Error", "Cannot access file.", null, null);
alert.setTimeout(Alert.FOREVER);
alert.setType(AlertType.ERROR);
display.setCurrent(alert);
catch( IOException error )
Alert alert = new Alert("Error", error.toString(), null, null);
alert.setTimeout(Alert.FOREVER);
alert.setType(AlertType.ERROR);
display.setCurrent(alert);
catch(Exception e)
System.out.println(e);
public void start()
Thread thread = new Thread(this);
try
thread.start();
catch(Exception e)
System.out.println(e);
}

Similar Messages

  • Thread creation error: Not enough storage is available to process this command

    Two user in my company have this problem, I have already used the solution on the community but would come back after 2 to 3 weeks. They all have the message "Thread creation error: Not enough storage is available to process this command". I tried increase the virtual memory to 4Gb, update one client to the latest, reset IRPStackSize, delete temp folder.  one client is 7.5.XX with windows 7 and another is 6.20.0.104 with Windows XP,My machine is also 6.20 with windows 7 but I dont have this problem.   

    Version previous to 7.6 worked fine. After update I have got this message and mostly of Skype GUI turns black or vanishes. No possibility of making more than one call before crash, It is amazing that a thread started about two weeks ago has no technical answer, at least. What do I do with my credits and my appointments? Throw them away?

  • Thread creation error: Not enough storage space

    Hi,
      Recently (the past week or so), my desktop client for Skype has been crashing regularly. This is accompanied by large (over 1.2GB) amounts of memory usage. At semi-regular intervals (say every few hours), Skype will post an error with the text "Thread creation error: Not enough storage space..."
    I am using the latest build of Skype. I am not performing any Skype logging. This error is clearly an ongoing issue which has not been addressed, as prior threads have discussed this as well.

    Errors like this have been addressed and continue to be addressed.  Being that the errors are related to memory leakage of one form or the other, the problem can have several sources and be agitated by several programs.  I personally run the latest version on all my machines in a 24/7 capacity and have not run into the problem.  Some versions in the past created a similar error for me, yet the latest has not.  If you've already updated your IE's flash and that has not alleviated the problem, the only other solution is running an earlier release that doesn't crash for you or restart Skype more often.  I've had virtual video devices trigger this behavior by simply launching the video settings once.  The virtual device even when not in use continued to consume memory under Skype until it crashed.  So if you use any virtual audio/video components you may want to remove them to see if that changes anything.  Some people have also blocked ads when those were the source.
    http://community.skype.com/t5/Windows-desktop-clie​nt/low-storage/m-p/3974193/highlight/true#M344826

  • Callbacks without excessive thread creation and memory leaks?

    Hi JNI experts,
    I haven't done any serious JNI programming in a couple years and I'm currently stuck with a tricky JNI problem:
    My JNI code is connected to a system driver and needs to do frequent callbacks into Java code. The standard way of doing this involves calling AttachCurrentThread and DetachCurrentThread before/after the callback to Java code. However, I noticed that AttachCurrentThread creates a new java.lang.Thread each time it is invoked. Let's just say that the callback is invoked from JNI very freqently, and creating a new Thread each time that happens is not acceptable behavior for my application. Among other things, it prevents me from using the Eclipse debugger because the large number of threads being created and destroyed effectively locks up Eclipse's debugger UI. Also, it creates a CPU load that is way higher than it should be for a light-weight operation.
    So, I deviated from the standard Attach/DetachCurrentThread pattern and moved the DetachCurrentThread to code that is only called when the native JNI service is terminated. As that effectively renders repeated AttachCurrentThread calls a no-op, the problem of excessive creation and destruction of threads went away, but instead I had a memory leak on my hands now. The JNI code needs to create some Java objects because it's easier to create those objects right away rather than passing a bunch of primitives to Java and assembling them into objects there. When I moved the DetachCurrentThread, those newly created objects were no longer garbage-collected even after the Java code had released all references.
    When you print the stack trace of the Java callback method there is always only one frame on the stack (since it is being invoked directly from JNI). However, I suspect that older stack frames from previous invocations keep hanging around somewhere else in memory if DetachCurrentThread is not called. In other words, moving DetachCurrentThread out of the callback is an even worse option. I tried using PopLocalFrame to get rid of left over stack frames, but that didn't seem to work.
    So, my question is: is there a way to make (natively initiated) callbacks from JNI to Java without memory leaks and without creating a new thread each time? Would it work if I created my own native thread that runs some sort of dispatch loop? What other options are there?
    Thanks for any ideas!

    Thanks for the quick reply, ejp! :-)
    Your comments were very helpful; let me clarify a few things:
    I don't know where you get this 'standard Attach/DetachCurrentThread pattern', but if the native callbacks always happen on the same native thread, you only need to attach it once when you get the first callback, and detach it when you get the last, if you can tell. ;-)Yes, the callback is always coming from the same native thread, but, unfortunately, I cannot tell when I get the last callback, and essentially the native service keeps running as long as the VM is running. When I say "standard pattern" I'm referring to the fact that pretty much every book, tutorial, or web site that talks about JNI callbacks shows code snippets where AttachCurrentThread is called, then the callback, and then DetachCurrentThread.
    The JNI code needs to create some Java objects because it's easier to create those objects right away rather than passing a bunch of primitives to Java and assembling them into objects there.Is it really? Are you sure?I'm pretty sure in this case, though your point is well taken. The native API that calls my JNI code produces packets of that contain about 15 pieces of information of different types (ints, longs, doubles). Several packets may arrive together in a single group. Handling the data on the Java side requires a Java callback method with 15 parameters for a single packet, and it's hard to reconstruct which packets belong to one group at that point. Creating corresponding Java objects in JNI and passing them inside an array to the callback function indeed turned out to be easier.
    I don't think just 'moving' the DetachCurrentThread is correct. You need to attach the thread that is doing the callbacks, as often as necessary but no oftener, and detach it when you can.I think I found the solution: my native code is starting a separate dispatcher thread that, as you suggested, attaches itself only once and then enters a dispatcher loop. The low-level call back function notifies that thread of new data via the standard Pthread API. The detach happens in JNI_OnUnload. This works without creating a new thread each time and garbage-collects the created objects properly. As the dispatcher method essentially never returns I also had to insert some DeleteLocalRef calls, because otherwise the local references prevented garbage collection.
    So, for now, it looks like I'm good to go. Thanks again for the reply!

  • Problem with Thread and InputStream

    Hi,
    I am having a problem with threads and InputStreams. I have a class which
    extends Thread. I have created and started four instances of this class. But
    only one instance finishes its' work. When I check the state of other three
    threads their state remains Runnable.
    What I want to do is to open four InputStreams which are running in four
    threads, which reads from the same url.
    This is what I have written in my thread class's run method,
    public void run()
         URL url = new URL("http://localhost/test/myFile.exe");
    URLConnection conn = url.openConnection();
    InputStream istream = conn.getInputStream();
    System.out.println("input stream taken");
    If I close the input stream at the end of the run method, then other threads
    also works fine. But I do not want to close it becuase I have to read data
    from it later.
    The file(myFile.exe) I am trying to read is about 35 MB in size.
    When I try to read a file which is about 10 KB all the threads work well.
    Plz teach me how to solve this problem.
    I am using JDK 1.5 and Win XP home edition.
    Thanks in advance,
    Chamal.

    I dunno if we should be doing such things as this code does, but it works fine for me. All threads get completed.
    public class ThreadURL implements Runnable
        /* (non-Javadoc)
         * @see java.lang.Runnable#run()
        public void run()
            try
                URL url = new URL("http://localhost:7777/java/install/");
                URLConnection conn = url.openConnection();
                InputStream istream = conn.getInputStream();
                System.out.println("input stream taken by "+Thread.currentThread().getName());
                istream.close();
                System.out.println("input stream closed by "+Thread.currentThread().getName());
            catch (MalformedURLException e)
                System.out.println(e);
                //TODO Handle exception.
            catch (IOException e)
                System.out.println(e);
                //TODO Handle exception.
        public static void main(String[] args)
            ThreadURL u = new ThreadURL();
            Thread t = new Thread(u,"1");
            Thread t1 = new Thread(u,"2");
            Thread t2 = new Thread(u,"3");
            Thread t3 = new Thread(u,"4");
            t.start();
            t1.start();
            t2.start();
            t3.start();
    }And this is the o/p i got
    input stream taken by 2
    input stream closed by 2
    input stream taken by 4
    input stream closed by 4
    input stream taken by 3
    input stream closed by 3
    input stream taken by 1
    input stream closed by 1
    can u paste your whole code ?
    ram.

  • Problem regarding the creation of Table using CSS.

    Hi ,
    Here I have a Problem regarding the creation of Table using CSS.
    In My Application i have a table with multiple rows(Rows are Dynamically added to the table).First i am setting the table with the following properties:
    width:900px;
    height : auto,
    Overflow : visible,
    Max-height: : 200px.
    If I use above properties,I'm getting a table with 5 or 6 rows(height upto 200px).After that i am getting the Vertical ScrollBar.
    The problem is when a table has many columns, Vertical and Horizontal Scrolls are coming at the time of setting the table. The table height is not Increasing dynamically.
    How can i use "height" property in CSS? (I want the table height to be increased when the columns are more.)
    Thanks & Regards
    Madhavi

    Hey humble user. Errr I'm trying to understand what ur trying to do. U want to create a section of a region destructively from an existing region right? If so select the option convert to new region (opt-comm-R or selecting it by right clicking). Check your audio bin to make sure. Whats the "merge" function? Are u refering to the glue tool?

  • Problem in Idoc creation in ME22N

    Hi All,
    We are facing a problem in Idoc creation in transaction ME22N.Our requirement is to trigger an output type and create a idoc everytime a change is made to a particular Purchase Order.
    Presently however,for some vendors,when we change the plant at the item level,an Idoc is not created(with a message that the changes are not relevant to create an Idoc).Any other change to the Purchase Order like changes in quantity or price,results in successful Idoc creation.
    We have also noticed that this happens only in the case of certain vendors.The Customer Info records and vendor data are all believed to be fine.
    Are any other config settings required to be maintained for this?
    Thanks in advance!
    Regards,
    Nejuma Iqbal

    Hi Nejuma,
    I don't think there is any problem with cofiguration settings.u r getting the idocs for some vendors .
    if iam not wrong u r giving LS in the tcode(we20).The method which u r using is change pointers.As u r using standard idoc all the settings will be done.
    Only settings u have to do is
    1>generate partner profiles(WE20)
    2>Distribute model view(BD64).
    REGARDS,
    Nagaraj

  • Regarding Thread Creation

    Hello,
    To create a thread in java there are two methods.
    (1) by extending from thread class.
    (2) by implementing runnable interface.
    implementing runnable interface is the preferred method to create a thread because we still have the option to extend from any other class.
    But does anybody know why java provides 2 methods for thread creation, why doesn't it provide only option 2 (i.e. by implementing runnable interface) when it is the preferred option.
    Regards,
    Sandy.

    Though Runnable interface is preferred to create threads in Java,most programmers extends Thread class.As jschell would say, 'I am rather certain' that the opposite is true.
    The reason behind of this is that you can have a clear logic of your code by using ThreadThat's not even true and it certainly isn't a reason to extend Thread rather than implement Runnable.
    most of the system programming written in java used Thread class instead of Runnable interface .If you have some evidence on the point please produce it. The consensus of opinion on these forums has been the other way round for many years.

  • Problem in billing creation

    hi dear,
    i have problem in billing creation,if i am making credit notes with reference to return order value of assassable value not copied.i have checked copying control for return order to billing doc its already maintained.
    regards
    ajit
    Edited by: SAP SD AJIT on Oct 22, 2009 11:58 AM
    Edited by: SAP SD AJIT on Oct 22, 2009 11:58 AM
    Edited by: SAP SD AJIT on Oct 22, 2009 11:59 AM
    Edited by: SAP SD AJIT on Oct 22, 2009 12:02 PM

    hi,
    please check the following fields in VTFA
    Data VBRK/VBRP - 002 (Ord-Rel Credit Memo)
    Pricing type - D (Copy pricing elements unchanged)
    regards
    senya

  • Thread creation questions

    I'm creating a diary type program (dates and times of various things) and am having a few problems creating threads. I'm understanding how to create the threads I think, but from what I've been able to understand, everything that the tread runs is in the run() method only. So how do I make it run other things?
    for instance, I have a search method which searches through a load of objects (the tasks). Can I run this search method in its own thread?
    Thanks
    Adrian

    agehoops wrote:
    Well I plan to put a GUI on the top of it so obviously that'll have its own thread but I don't want anything to lock up while it's searching through potentially hundreds of objectsThat's a little better. If you are using Swing and Java 6, have a look at using a SwingWorker object. It smooths over some of the difficulties of doing Threading with Swing. There's a decent tutorial on using this here:
    [Lesson: Concurrency in Swing|http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html]

  • RoboCode crashes with SeedGenerator thread creation error?

    Hello everyone.
    I recently came across a game called RoboCode. It seems to be a tank battle simulator where you write the AI in Java.
    Unfortunately, it won't start on my Windows computers. I get this error:
    Exception in thread "SeedGenerator Thread" java.lang.InternalError: internal error: SeedGenerator thread creation error.
            at sun.security.provider.SeedGenerator$ThreadedSeedGenerator.run(Unknown Source)
            at java.lang.Thread.run(Unknown Source)Anyone got any idea why? I haven't the foggiest clue how to fix it or get around it - or even what it means.
    Thanks,
    -Kramy

    I'm awaiting a reply right now.
    But if Google couldn't turn up much, then it probably isn't a very common error? ;)

  • Creation  of components in dinamic way. Problem with threads....?

    hi,
    I am trying to add components (JTextFields) to a JPanel in dynamic way.
    I would like that the user decides the number of the components, to
    be created, for executing a function by clicking a button.
    But clicking on the button, the elaboration doesn't produce the creation
    of the JTextFields.
    Debugging the code I saw that the same function works well
    when it is called from the normal data flow of the elaboration
    instead that it is called from inside a listener.
    It is hard for me to understand the reason why this
    happens, as well I could think that this problem could happen
    because the execution of different threads.
    But I am not able to manage those kind of situations....
    I would like to have a little help
    thank you
    regards
    tonyMrsangelo.
    To reproduce the problem I post some code where the function (setComponentInThePanel())
    is called from the constructor of the class and from the listener of a JButton.
    package labels;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JSpinner;
    import javax.swing.JTextField;
    import javax.swing.SpinnerNumberModel;
    public class LabelsDialogMain extends JFrame {
        PanelCanvas jPanCanvas = new PanelCanvas();
        PanelDesign jPanDesign = new PanelDesign();
        PanelCommands jPanCommands = new PanelCommands(jPanDesign);
        /** Creates new form MainLabelsDialog */
        public LabelsDialogMain() {
            java.awt.GridBagConstraints gridBagConstraints;
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            getContentPane().setLayout(new java.awt.GridBagLayout());
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 0;
            gridBagConstraints.gridy = 0;
            gridBagConstraints.gridwidth = 2;
            gridBagConstraints.gridheight = 2;
            getContentPane().add(jPanCanvas, gridBagConstraints);
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 3;
            gridBagConstraints.gridy = 0;
            gridBagConstraints.gridwidth = 2;
            gridBagConstraints.gridheight = 2;
            getContentPane().add(jPanDesign, gridBagConstraints);
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 1;
            gridBagConstraints.gridy = 2;
            gridBagConstraints.gridwidth = 4;
            gridBagConstraints.gridheight = 2;
            getContentPane().add(jPanCommands, gridBagConstraints);
            pack();
         * @param args the command line arguments
        public static void main(String args[]) {
             LabelsDialogMain mld = new LabelsDialogMain();
             mld.setVisible(true);
    class PanelCanvas extends JPanel {
        public PanelCanvas() {
            Dimension d = new Dimension(400,200);
            setPreferredSize(d);
            setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Panel Canvas", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Comic Sans MS", 0, 11), new java.awt.Color(0, 255, 255))); // NOI18N
    } // class PanelCanvas
    class PanelDesign extends JPanel {
        JTextField textField [];
        public PanelDesign() {
            Dimension d = new Dimension(400,200);
            setPreferredSize(d);
            setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Panel Design", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Comic Sans MS", 0, 11), new java.awt.Color(0, 255, 255))); // NOI18N
        void setComponentInThePanel(int dim ){
             textField = new  JTextField[dim];
             for (int i = 0; i < dim; i++){
                 textField[i] = new  JTextField("----- " + i);
                 add(textField);
    System.out.println("executed the nmbr: " + i);
    repaint();
    } // setComponentInThePanel()
    } // class PanelDesign
    class PanelCommands extends JPanel {
    PanelDesign panelDesign;
    private javax.swing.JLabel jLblRowNmbr;
    private javax.swing.JSpinner jSpinner;
    JButton dummyButton = new JButton("button");
    public PanelCommands(PanelDesign pnlDesign) {
    panelDesign = pnlDesign;
    Dimension d = new Dimension(800,200);
    setPreferredSize(d);
    setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Panel Cmmands", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Comic Sans MS", 0, 11), new java.awt.Color(0, 255, 255))); // NOI18N
    jLblRowNmbr = new javax.swing.JLabel();
    jSpinner = new JSpinner();
    jLblRowNmbr = new JLabel();
    add(jLblRowNmbr);
    add(jSpinner);
    add(dummyButton);
    jSpinner.setModel(new javax.swing.SpinnerNumberModel(Short.valueOf((short)1), Short.valueOf((short)1), null, Short.valueOf((short)1)));
    final SpinnerNumberModel sm = (SpinnerNumberModel) this.jSpinner.getModel();
    jLblRowNmbr.setText("N. of the rows");
    // panelDesign.setComponentInThePanel(4); "take out the comment of this row to get the creation of JTextFields"
    dummyButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    Number amp = sm.getNumber();
    int ampInt = amp.intValue();
    panelDesign.setComponentInThePanel(ampInt);
    // panelDesign.setComponentInThePanel(4);
    JOptionPane.showMessageDialog(jSpinner, "spinner = " + ampInt);
    } // class PanelCommands

    When you add/remove components to a panel when the GUI has already been created then you need to use:
    panel.revalidate();
    panel.repaint();

  • Problem with InitialContext Creation in Weblogic 5.1

    Hi all,
    We are using Weblogic 5.1 on Windows and Solaris.
    We are trying to get InitialContext by the following code snippet.
    This piece of code is in a Thread which is kicked off by a startup class.
    The purpose of getting the initialContext here is to get a reference to a JMS
    queue and to start listening for any messages that are put into the queue.
    Hashtable htEnv = new Hashtable();
    htEnv.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
    htEnv.put(Context.PROVIDER_URL, "t3://ip_address:port_number");
    return new InitialContext(htEnv);
    Sometimes this code takes almost 15 minutes to return an InitialContext.
    Some other times it does not return at all, neither does it throw any exception.
    In the application this code may get called multiple times simultaneously.
    The problem is not consistent also.
    There is one aspect that has been noticed. A number of InitialContext Objects
    are initiated in the application and are not closed after use (As recommended
    in the weblogic documentation).
    The other observation is that the occurrence of the above explained problem is
    very consistent when the executeThreadCount of the Weblogic server is low (<=
    15). However, once the executeThread count is increased to a higher value (30
    to 45) the occurrence of the problem is very rare.
    Any information regarding this problem would be extremely helpful.
    Thanks and Regards,
    Uday

    Thank you Bhagvan,
    The creation of initial context in every call is a clear mistake. Caching has
    to be implemented.
    However , i need some more information about this ....
    As you said the initial context is being created at every instant for a lookup
    of any object in the jndi tree in the remote machine(I'll name this "machine A").
    Simultaneously there is an attempt for creation of an InitialContext in the other
    machine(call it "machine B") for the remote "machine A".
    This is needed because "machine B" has to get a reference to a JMS queue on "machine
    A" and start listening for any messages in it.
    It is at this point that the InitialContext creation takes randomly long times
    to return.
    That is the call is made by populating a Hashtable with the properties of the
    remote "machine A" like the IP address, Port number of "machine A" and using this
    Hashtable as a parameter in "machine B" to get the InitialContext.
    I was also wondering if there is a limit on the number of InitialContext objects
    that can be opened at any instant in a server.
    Could you please throw more light on these areas ........
    Thanks and regards,
    uday
    "bhagvan" <[email protected]> wrote:
    >
    Is there any particular reason why you want to get
    a new initial context in every call ?? My suggestion
    is to cache it based on the application parameters let us
    say the client user or client's machine or any other parameter
    which is unique for a client.
    hope this helps.
    "Uday Reddy" <[email protected]> wrote:
    Hi all,
    We are using Weblogic 5.1 on Windows and Solaris.
    We are trying to get InitialContext by the following code snippet.
    This piece of code is in a Thread which is kicked off by a startup class.
    The purpose of getting the initialContext here is to get a reference
    to a JMS
    queue and to start listening for any messages that are put into thequeue.
    Hashtable htEnv = new Hashtable();
    htEnv.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
    htEnv.put(Context.PROVIDER_URL, "t3://ip_address:port_number");
    return new InitialContext(htEnv);
    Sometimes this code takes almost 15 minutes to return an InitialContext.
    Some other times it does not return at all, neither does it throw any
    exception.
    In the application this code may get called multiple times simultaneously.
    The problem is not consistent also.
    There is one aspect that has been noticed. A number of InitialContext
    Objects
    are initiated in the application and are not closed after use (As recommended
    in the weblogic documentation).
    The other observation is that the occurrence of the above explainedproblem
    is
    very consistent when the executeThreadCount of the Weblogic server is
    low (<=
    15). However, once the executeThread count is increased to a highervalue
    (30
    to 45) the occurrence of the problem is very rare.
    Any information regarding this problem would be extremely helpful.
    Thanks and Regards,
    Uday

  • A problem with threads

    I am trying to implement some kind of a server listening for requests. The listener part of the app, is a daemon thread that listens for connections and instantiates a handling daemon thread once it gets some. However, my problem is that i must be able to kill the listening thread at the user's will (say via a sto button). I have done this via the Sun's proposed way, by testing a boolean flag in the loop, which is set to false when i wish to kill the thread. The problem with this thing is the following...
    Once the thread starts excecuting, it will test the flag, find it true and enter the loop. At some point it will LOCK on the server socket waiting for connection. Unless some client actually connects, it will keep on listening indefinatelly whithought ever bothering to check for the flag again (no matter how many times you set the damn thing to false).
    My question is this: Is there any real, non-theoretical, applied way to stop thread in java safely?
    Thank you in advance,
    Lefty

    This was one solution from the socket programming forum, have you tried this??
    public Thread MyThread extends Thread{
         boolean active = true;          
         public void run(){
              ss.setSoTimeout(90);               
              while (active){                   
                   try{                       
                        serverSocket = ss.accept();
                   catch (SocketTimeoutException ste){
                   // do nothing                   
         // interrupt thread           
         public void deactivate(){               
              active = false;
              // you gotta sleep for a time longer than the               
              // accept() timeout to make sure that timeout is finished.               
              try{
                   sleep(91);               
              }catch (InterruptedException ie){            
              interrupt();
    }

  • 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

Maybe you are looking for

  • Run CF10 Developer in Standard Edition mode

    Is there a way to run ColdFusion 10 Developer in Standard mode for testing? My main concern is the Oracle drivers and if the standard edition will meet our needs, but would like to test it before purchasing what could be the incorrect license.

  • Can you order a book from the trial version?

    I've searched this forum and been surprised not to find this question: Can I order a book using the trial version of Aperture? Got myself in a pickle where iPhoto '09, My Publisher and other methods are not giving me the results I need, and I'm on a

  • EJB and JNI

    I have a product write by JNI to call some java object on server side. Like VB -> JNI bridge -> client jar -> (RMI) -> server. Now the server was changed to J2EE & EJB2.1. The procedure become VB -> JNI bridge -> client jar -> (EJB) Server I tried to

  • Incompatible types in CMP .. How to read RAW

    MY CMP bean has a few CMP fields which are of type byte[] in the database i created dbfields having RAW datatype. Deployment is Successfull. but when i try to create this CMP then the ejbexception is thrown and it is having a nested exception SQLExce

  • Redness in retina display

    I had issues with my macbook pro putting a "read mask" over many images and menus.MSWord and Pages looked positively pink. I did some searching on the intertubes and in the forums and found nothing but lots of complaints about color on Macbook pros.