HttpConnection blocking ALL MIDlet threads?

Hi there,
Geez, I am pretty depressed as I seem to be too incompetent to implement the most basic HttpConnection use case. My MIDlet needs to issue a single HTTP POST request during the complete MIDlet lifetime. Pretty basic, one should think. I spawn a main thread for the MIDlet, from the main thread I spawn a thread for the HTTP connection. However, once the connection thread blocks, the main thread seems to block, too. Let me give you some minimal code that reproduces this behaviour.
Here's the MIDlet. It simply creates the main thread in startApp().
import javax.microedition.midlet.MIDlet;
public class Connection extends MIDlet
     protected void destroyApp(boolean force)
     protected void pauseApp()
     protected void startApp()
          System.out.println("Starting main thread");
          new Thread(new MainThread()).start();
}Here's the main thread. It just creates the connection thread and then either sleep()s for 5000 ms or wait()s for 5000 ms. It also measures how long the sleep() or wait() actually took. The idea is to go back to the user after the timeout and tell him/her, sorry, it did not work out. That's enough for me. I don't even have to shut down the connection thread.
public class MainThread implements Runnable
     private synchronized void waitFor5000ms()
          try
               wait(5000);
          catch (InterruptedException ex)
               ex.printStackTrace();
     private void sleepFor5000ms()
          try
               Thread.sleep(5000);
          catch (InterruptedException ex)
               ex.printStackTrace();
     public void run()
          System.out.println("Main thread method entered, now starting HTTP thread");
          new Thread(new HttpThread()).start();
          System.out.println("HTTP thread started, now waiting for 5000 ms");
          long startTime = System.currentTimeMillis();
          if (true)
               waitFor5000ms();
          else
               sleepFor5000ms();
          long duration = System.currentTimeMillis() - startTime;
          System.out.println("Waited for 5000 ms, which took us " + duration + " ms");
}And here's the code for the connection thread. For the sake of brevity it only contains the statements that are required to reproduce the problem. I am deliberately using an IP address that does not exist in my test network to see how my code behaves under this error condition.
import java.io.IOException;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.io.StreamConnection;
public class HttpThread implements Runnable
     public void run()
          try
               System.out.println("Connection thread method entered, now opening connection");
               StreamConnection streamConnection = (HttpConnection)Connector.open("http://192.168.123.234/blah.html");
               System.out.println("Connection opened, now setting request method");               
               ((HttpConnection)streamConnection).setRequestMethod(HttpConnection.POST);
               System.out.println("Request method set, now opening output stream");
               OutputStream out = streamConnection.openOutputStream();
               System.out.println("Opened output stream, now writing byte");
               out.write(0);
               System.out.println("Wrote byte, now flushing output stream");
               out.flush();
          catch (IOException ex)
               ex.printStackTrace();
}So, here's how the code behaves. The out.flush() method invocation in the connection thread blocks, as it causes the HTTP connection to get established. HOWEVER, the main thread blocks, too. So, the sleep() or wait() does not take about 5000 ms, but more than 20000 ms. The main thread seems to only continue executing once out.flush() returns. Bizarre. Here's the output of the MIDlet. It is basically the same for WTK 2.2 (Windows and Linux), WTK 2.5.1 (Windows), and the SonyEricsson SDK 2.2.4 (Windows).
Running with storage root temp.DefaultColorPhone44
Running with locale: English_United States.1252
Running in the maximum security domain
Starting main thread
Main thread method entered, now starting HTTP thread
HTTP thread started, now waiting for 5000 ms
Connection thread method entered, now opening connection
Connection opened, now setting request method
Request method set, now opening output stream
Opened output stream, now writing byte
Wrote byte, now flushing output stream
javax.microedition.io.ConnectionNotFoundException: TCP open
     at com.sun.midp.io.j2me.socket.Protocol.connect(+99)
     at com.sun.midp.io.ConnectionBaseAdapter.openPrim(+52)
     at com.sun.midp.io.j2me.socket.Protocol.openPrim(+108)
     at com.sun.midp.io.ConnectionBaseAdapter.openPrim(+14)
     at com.sun.midp.io.ConnectionBaseAdapter.openPrim(+8)
     at com.sun.midp.io.j2me.http.Protocol.connect(+73)
     at com.sun.midp.io.j2me.http.Protocol.streamConnect(+57)
     at com.sun.midp.io.j2me.http.Protocol.startRequest(+12)
     at com.sun.midp.io.j2me.http.Protocol.sendRequest(+38)
     at com.sun.midp.io.j2me.http.Protocol.flush(+36)
     at com.sun.midp.io.BaseOutputStream.flush(+11)
     at HttpThread.run(+76)
Waited for 5000 ms, which took us 21000 ms
Execution completed.
3423649 bytecodes executed
354 thread switches
1669 classes in the system (including system classes)
17953 dynamic objects allocated (546852 bytes)
3 garbage collections (465956 bytes collected)
I must be missing something pretty obvious as this is really pretty basic, isn't it? Any thoughts?
Thanks,
Thomas

Hey sailesh_dit,
Thanks for confirming this problem. So, it seems more and more to me that this is a general problem with at least some VMs and/or WTKs and not my fault. My current guess is that a blocking native call messes up the VM. Maybe I should open another thread with this as a subject.
I was just a bit surprised that this wasn't discussed anywhere. Everywhere I read "Run your networking code in a separate thread!" and nobody seemed to have run into problems with this approach, which left me a little confused. So, it is good to hear that you've also experience this problem.
Thomas

Similar Messages

  • Win 8.1 domain workstation. Block all access, except for a fews users/groups and domain controller information/date.

    Hi!
    Win 8.1 pro, domain workstation. How Block all access, except for a fews users/groups and domain controller information/date.
    Nuance:
    From domain AD is locked Workstation Firewall "Domain profile" edit.
    Possible?
    cenubit

    Hi GirtsR,
    I am not sure the command to use the SID to accomplish what you want to achieve, if you only know the SID, you could take use Powershell to find the related information, more information, please check:
    Working with SIDs
    And a similar thread for reference:
    How to find user/group known only SID
    More reference: Default local groups.
    Best regards
    Michael Shao
    TechNet Community Support

  • How to blocks the main thread

    Hello,
    I have a multi-threaded application but the main thread doesnt blocks the application so the application quits just after started. Im using this code to block the main thread:
    /*BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
    for(;;) {
    try {
    r.readLine();
    catch (IOException e) {
    I tryed to just use for(;;){} but it causes 100% of CPU using. This code above its very dangerous because sometimes System.in blocks the entire application (all threads)
    Thanks a lot

    This application its a socket server, Im doing:
    main {
    Thread1 - createServer();
    Thread2 - createLogging();
    waitForServerShutDown();
    the createServer method must be placed in a thread, its must not blocks the application because createLogging(); must be executed just after the server was created and createLogging(); doesnt blocks the application then... I must block the main{} to keeps application running

  • JFileChooser blocks all JFrames

    I believe something like this was asked before already, but I could not find a satisfactory solution.
    Situation:
    I have X JFrames open. Each frame has a "Browse" button and a "New Window" button, and some content like an image or text. Clicking "Browse" opens a new JFileChooser, and "New Window" opens a new JFrame like all the others.
    Problem:
    Whenever I click "Browse" in one of the JFrames, I cannot interact with ANY JFrame until the JFileChooser is closed. Clicking buttons has no effect, and no ActionEvents are delivered to either parent window or other windows. Similarly, if the program cannot open the file chosen it displays an error dialog which behaves in exactly the same way, blocking all windows and not just the parent window like would be logical and acceptable.
    Failed solution:
    In the beginning of the actionPerformed method I start a new thread to actually handle the ActionEvent. I have verified that the actionPerformed method finishes before the JFileChooser is closed, so I know the opening of the filechooser is not blocking the event dispatching thread. I also ran the SwingUtilities check to see whether the JFileChooser opening was running in the event dispatching thread and the result was false.
    As far as I can see everything should be ok, but still all my JFrames remain blocked if any of them opens up a JFileChooser or a message window.
    Can anyone help?

    The dialog created by JFileChooser.showOpenDialog() is made modal
    on purpose, so that the return value can be retrieved in a single
    threaded flow without having to set listeners etc.
    You can embed a JFileChooser in your own JDialog and not make it
    modal if you want to. Add a PropertyChangeListener to catch the
    APPROVE_SELECTION and CANCEL_SELECTION events, or override
    the approveSelection() and cancelSelection() methods.
    Leif Samuelsson
    Java Swing Team
    Sun Microsystems, Inc.

  • Want block all online video stream and chat.

    I want to block all video Stream and chat messengers in my laptop irrespective of browsers, my room met always watching porn, you-tube, cricket, movies and soccer videos. I tried blocking IE using content adviser by the help of my colleague, but he installed
    chrome and watching. Please suggest me a way where i can block the online stream access in system level.

    Hello,
    To block sites, check the following links given below, I hope it helps you:
    http://windows.microsoft.com/en-AU/windows-live/family-safety-child-kid-protect-filter-sites-chat-faq
    OR
    http://www.pcworld.com/article/249077/how_to_block_websites.html
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

  • Block all currencies except GBP

    Hi All,  I appreciate this may be a little unconventional, but my company wants only to use GBP in their system, 
    They currently use MM Purchasing, ISH - healthcare module, SD and others as well as the finance suite.
    is there an easy way to block all currencies across the system apart from GBP?
    I'm considering setting all currencies as expiring currencies except GBP but any other suggestions would be very welcome
    thanks
    Phil

    I am afraid to delete the currencies in TCURR table, as they are client independent and if tomorrow for any reason you need multiple currencies, then it would be an issue.
    Therefore, please look into the following threads and check with your ABAPer:
    Validation rule in Purchase Order to error a G/LAcct with Acct Assign Cat K
    ME21n T code Validate through GGB0 or OKC7
    Validation during PO entry(GL Account in ACcount assignment)

  • Kill all childen threads on close?

    In my jfx2 app I have a thread that gets stood up. When I click the [X] for the main application window I want all "child threads" to be killed. Is this possible? I have not seen anything in the tutorials to describe this nor a way to override a "onClose" like method? Any help would be great.
    Riley

    Use childThread.setDaemon(true) for all child threads:
    (http://www.jguru.com/faq/view.jsp?EID=43724 "What is a daemon thread? When should I use setDaemon() and why?")
    If it is not possible to use a Daemon thread, implement logic in an onHidden event handler to notify the threads that they need to shutdown, implement logic in the threads to handle the shutdown notification, and join to each of the threads to await their completion or use a CountDownLatch. If you do this you might want to do the join or CountDownLatch wait in it's own seperate shutdown thread so as not to block the JavaFX application thread.
    http://docs.oracle.com/javafx/2.0/api/javafx/stage/Window.html#setOnHidden%28javafx.event.EventHandler%29
    http://javahowto.blogspot.com/2007/05/when-to-join-threads.html
    http://javahowto.blogspot.com/2011/08/when-to-join-threads-with.html
    Or, if there would be no adverse consequences, you can just call System.exit as aidreamer suggests.

  • F110 Blocking all Invoices on a Vendor due to one Un-released PO.

    Hi All,
    We are implementing Vendor Downpayment functionality. I have done all the configuration and we did not activate the business object LOG_MMFI_P2P. We are just using the conventional Vendor Downpayment functionality. We get POs created from SRM. I am getting an error message when I am trying to run Payment run for a vendor for which I have created multiple PO's. Few PO's have Down Payment requests and few do not have. For one PO I created an invoice twice the amount of PO amount, so it went on unreleased status in SRM. Then when I ran the Payment run F110 for that vendor, the payment run is blocking all the other Invoices as well even though they are for different PO's.
    Here is what I did
    1) Created a PO for $100 from SRM
    2) Created a Down Payment request of 50$ for that PO in F-47 and did not process the down payment. Now I processed MIGO for 100$, then created an invocie for 100$. Now i have created another invoice for $100 and posted that invoice. It went on payment block and i released the Payment block for that invoice in MRBR. Since the invoice amount is greater than PO amount in SRM the PO went on un released status and same in SAP as well.
    3) Parallely I have created few other PO's and Invoices for the same vendor without any down payment requests.
    4) Now when I ran F110 for this vendor, due to the unrelased status of one single PO, all other invoices are getting blocked in F110 run. I am not sure why is this happening, any help would be greatly appreciated.
    The errors I am getting are
    Purchasing document XXXX not yet released
    Purchase order XXXXX (assigned to an account) not permitted
    Information re. vendor XXXX/ paying company code XXX...
    Message no. ME390
    Message no. FZ356
    Thanks,
    Uday

    Hi Ramesh,
    Strange error..
    anyways, you have option in Payment Tab to Individual Payment. This will consider each individual posting a separate payment.
    Thanks,
    Deepanshu

  • How can I get Verizon to block all outgoing messages on my email?

    My email was apparently hacked, it is the main account that I have used for the past seven years and all of my bill notifications and important things come to this address.  I have changed the password repeatedly, run several scans on my main computer, laptop, kindle fire, and cell phone (every device I access the email on) using Norton and Norton Power Eraser on the computers.  Nothing showing up.  
    I chatted with support just now asking them to block all outgoing email and they said it isn't possible and I find that impossible to believe.  I am seeing all kinds of messages here saying that people are being blocked but I can't add an email address to that list?  I need to keep it active for inbound email for a month or so just to make sure that I haven't missed any bill notices or other important stuff.  Any ideas?
    Thanks!

    Pretty hard to do without shutting down the account.
    Assuming you have properlly changed your password, and checked your PC and other devices for viruses/trojatns/etc. Then the person using your email is probably NOT even using Verizon.  \
    Unfortunately the basic SMTP protocol is totally different then most people think.  Who you say you are is not a protected value and you can say you are anyone, yes verizon's servers when initially accepting input do check, but that is about it.  And the displayed sender and addresses in the smtp protocol do not have to match any text in the mail. that you see.
    Typical smtp conversation
    EHLO
    a bunch of auth commands
    MAIL and whoever i claim to be
    RCPT
    [email protected]
    [email protected]
    DATA
    this is what most people is the email and its headers, but can really be anything.
    FROM:  SOMEone
    TO:  you and everyone else they can think of

  • I am recieving calls from a solicitor. Show up as no caller Id. I want to block all calls that do not show caller Id. Can I do that? I am on the do not call list

    How do I block all in coming calls that do not show on my caller Id. Phone says "no caller id" This particular call is from a place selling septic tank cleaner. They leave an automated voice mail. They are calling me over and over. I am on the national do not call list but that's no help. Because the caller id doesn't show anything I can't even report them.
    I remember in the past calling a number and before my call would go thru I would have to enter my phone number so the party I was calling knew who was calling them. That is what I want to do. I want to block all calls from "no caller id" "number unavailable" Just FYI my phone is an IPHONE 5 and I am on Verizon.
    Any help would be appreciated.
    Thanks

        itbitybob, good day!
    Thank you for taking the time to reach out to us today. I know how frustrating it can be getting phone calls from "no caller id" numbers. We do have an option that is called Family Base that will allow you to block unknown numbers, private numbers, or caller id. This link will provide you with the full details of this option. http://vz.to/1gIklla I hope this is able to answer your question. If you have further questions please feel free to reach back out to us at any time.
    KevinR_VZW
    Please follow us on Twitter @VZWSupport 

  • How can I block all other mail account just to only use the exchange mailbox of our company? This is to prevent the user to setup his on company iPhone.

    How can I block all other mail account just to only use the exchange mailbox of our company? This is to prevent the user to setup his on company iPhone.

    I don't know if I'm asking this all in a way that can be understood? Thanks ED3K, however that part I do understand (in the link you provided!)
    What I need to know is "how" I can separate or rather create another Apple ID for my son-who is currently using "my Apple ID?" If there is a way to let him keep "all" his info on his phone (eg-contacts, music, app's, etc.) without doing a "reset?') Somehow I need to go into his phone's setting-create a new Apple ID and possibly a new password so he can still use our combined iCloud & Itunes account?
    Also then letting me take back my Apple ID & password, but again allowing us (my son and I) to use the same iCloud & Itunes account? Does that make more sense??? I'm sincerely trying to get this cleared up once and for all----just need guidance from someone who has a true understanding of the whole Apple iCloud/Itunes system!
    Thanks again for "anyone" that can help me!!!

  • How do i remove the airplay option from the screen saver on my apple tv.  Its blocking all my pictures

    The Airplay Screen saver option telling me to choose a wi fi and choose this apple tv keeps poping up on my apple tv when it goes on screen saver mode.  It blocks all of my photos showing on my screen saver.  Can anyone help me to remove this

    Welcome to the Apple community.
    Assuming that both devices are connected to the same network and that airplay is not turned off in your Apple TV settings, then you should be able to see the airplay icon when playing content on your iPad, by tapping the screen to reveal the playback control bar.
    If you do not see the airplay icon when you do this, you might try restarting the iPad, the Apple TV and your router.

  • Do you have an option for block all incoming message and request EXCEPTED messages from my contacts?

    Please help!!To whom it may concernDear Madam/Sir who works for Skype & Microsoft  Dear all who can really help,  Do you have an option for block all incoming message and request EXCEPTED messages from my contacts? or Do you have any solution to solve my problem from begin to now in present time?  Even though, I set the Privacy settings: - Allow calls from... "people in my Contact list only"- Automatically received video and share screens with "people in my Contact list only"- Allow IMs from "people in my Contact list only"  I still received unknow users sent me messages in every day, contact requests etc. And they're all clearly spammings and identity thefts.  I only wanna contact with my family and my freinds here with Skype via my Windows device and my mobile phone (w/Android OS).  And this is the only way to contact with them, because they could use Skype only in overseas.  BUT I don't need new friend from other unknow Skype member.   I keep blocked all unknow spammers in every day.  However in this morning, I feel so scared with Skype on my mobile, I looked at my mobile Skype, I saw it automatically showed me the list of all blocked members. BUT they were all unblocked (contact unblocked) by my mobile (Android version) Skype itself automatically, and listed them one by one on the screen, and about 30 seconds later, they all were disappeared suddenly.  I don't know what do to now, is it indicating my account was hacked?And how could I found out all those members again and block them again and delete all of them for ever?  I appreciate if you would improve the privacy protection. Thank you very very very much. 

    Hrm... that may be true and this may be a function of the phone email client that Apple just doesn't do.
    No, I can easily MANUALLY delete the messages. I would prefer if I didn't have to do it twice, tho. Once on the mail server and once on the phone.
    What I think the phone needs to do is, when it checks the POP, anything NOT there should be removed locally. I think you are correct on POP; the phone will poll the mx (mail exchanger) and the mx will pass off the messages to the phone. The phone then keeps ALL of that unitl you manually delete it.
    If, say, I remove a message from the mx, I would like the phone, when next polls, to see that that particular message isn't on the server anymore and remove it locally.
    Perhaps it's just me but if I delete the message on the mx itself, via my ISP's webmail interface, I really don't want to have to remove it again from my phone.
    thxs!
    cheers
    rOot

  • How to create a new rule in Windows Firewall to permit some specific IPs and block all other computers

    Hello,
    I have a Win7 PC. I want to block all incoming connections except 3 or 4 IPs. How can i do this?
    I created a new rule to block all connections using this steps:
    Inbound rules > New Rule > Custom > All Programs > All Protocols / Ports > All Local/Remote IPs > Block the connectiion > All profiles > Then i gave a name
    This rule works fine and blocks all incoming connections.
    Then i want to create a new rule to allow specific IPs using this steps:
    Inbound rules > New Rule > Custom > All Programs > All Protocols / Ports > Remote IPs: 192.168.10.5, 192.168.10.10 > Allow the connection > All profiles > Then i gave a name
    But 192.168.10.5 and 192.168.10.10 couldn't reach W7 machine. 
    (If rules are disabled or FW is off; both IPs could reach W7 machine)
    Thanks

    Hi,
    How did you check these two IP address? Through remote access? According to your description, it should only allow remote IP could access this computer. Please also allow local IP for test.
    Roger Lu
    TechNet Community Support

  • Hi Dude,     I ve seen all the threads from first to last even am gonna geta iphone 4s from Thailand. Would like to know which sim will be working fine in chennai as you all are using d phone for past many days???  Is it advisable to buy a phone

    Hi Dude,
    I ve seen all the threads from first to last even am gonna get a iphone 4s from Thailand. Would like to know which sim will be working fine in chennai as you all are using d phone for past many days???  Is it advisable to buy a phone from abroad.

    Thanks for that. Much more constructive than the last comment. It's only the restriction code I can't recall, not the access passcode. So I can currently access the device, just not age restricted content. Does that's make a difference? I also wondered if anyone knew how many attempts you get to try to get it right. Now tried 21 times and so far nothing bad has happened but I am concerned I'll eventually be completely locked out of the device. That doesn't seem in the spirit of things though. Surely it's foreseeable that a child could repeatedly try to guess the code so I can't see that it would be right to lock the device down completely in that circumstance, particularly if the access code is being typed in correctly every time.
    Thanks

Maybe you are looking for