waitForCardPresent() within thread freezes applet under Ubuntu
Hello,
I am currently having some issues with the waitForCardPresent() function in an applet.
I am developping an applet that manages PC/SC communications.
In my applet I need to check card Status.
To do I use a Thread , I have created a CardStatus class that manages the work of the thread (this class extends Thread).
Here is how I start my thread :
Code:
cs = new CardStatus();
cardStatusThread = new Thread(cs);
cardStatusThread.start();
I use EventListeners to notify my applet once waitForCardPresent() has finished.
The run() of my thread consists of (I have simplified the code) :
Code:
while(true)
{
if(Reader != null)
{
try {
if(!Reader.isCardPresent()) // the reader is set by the applet using a SetReader() function defined in CardStatus class
{
Reader.waitForCardPresent(0);
this.NotifyPresentListeners(); // this function notifies the applet that a card has been found
}
} catch (CardException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
This applet is signed.
I successfully manage to run this applet using windows, but I can't when using Ubuntu : the applet freezes until I put a card in the reader.
I have tried to replace the Reader.waitForCardPresent(0); instruction with Thread.sleep(50000); to check if there was a mistake from the way I was using my thread, in that case my applet doesn't freeze under Ubuntu ; so I am guessing that it is the waitForCardPresent function that causes the trouble.
I know that it could not be a security issue, because I have created an un signed applet that uses WaitForCardPresent (not within a thread, within the main code of the applet, just to test this) and I had no problem with it.
Last edited by emilie.c@pro-active.fr; April 21st, 2010 at 02:00 AM.
Reason: code tags
Re: waitForCardPresent() within thread freezes applet under Ubuntu
The CardTerminal.waitForCardPresent method (you didn't say, but I guess this is the one you mean) blocks indefinitely (until you put a card in) if you give it an argument of zero.
The outcome of any serious research can only be to make two questions grow where only one grew before...
T. Veblen
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
Re: waitForCardPresent() within thread freezes applet under Ubuntu
OK. Unfortunately I don't know how Ubuntu handles Java threading & blocking IO operations.
Perhaps someone with Ubuntu experience can help.
It's easy to cry "bug" when the truth is that you've got a complex system and sometimes it takes a while to get all the components to co-exist peacefully...
D. Vargas
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
Re: waitForCardPresent() within thread freezes applet under Ubuntu
You may want to check the CPU usage to check to see if the applet is freezing through the main thread being suspended/blocked or if it is because the background thread is using all the available CPU resources?
BTW you may want to put a short sleep in your while loop or better still call the waitForCardAbsent() method otherwise when the card is present your background thread is going to go around and around the loop chewing up CPU resources until the card is removed.
Bookmarks