aspose file tools*
The moose likes Threads and Synchronization and the fly likes Implementing thread in an applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Implementing thread in an applet" Watch "Implementing thread in an applet" New topic
Author

Implementing thread in an applet

vikram kamath c
Greenhorn

Joined: Jun 20, 2009
Posts: 15
I have 4 functions

function1() function2() function3() function4() called in init()

how do i call them simultaneously without editing major part of the code

Please help .... i know it involves threads but i am not able to implement it right

Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42592
    
  65
Moving to a more appropriate forum, since there's nothing applet-specific about the question.


Ping & DNS - my free Android networking tools app
James Ward
Ranch Hand

Joined: Apr 27, 2003
Posts: 263
How about using inline thread.

//inside your init method, if you do this - you can run your function1 code in a separate thread:

new Thread(
new Runnable() {
public void run() {
try {
//Your function1 code here.
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();

vikram kamath c
Greenhorn

Joined: Jun 20, 2009
Posts: 15
now the applet works fine in applet viewer simultaneous function call but does not work for browser even after signing .... help
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Give the Details. 'It doesn't work' doesn't help us with your problem. What doesn't work? What error? If nothing gets displayed on screen then look at your browser's Java consol to see what messages are displayed.


Steve
vikram kamath c
Greenhorn

Joined: Jun 20, 2009
Posts: 15
no error on java console/applet.....the threads don't start at all on the browser ..... the program just ignores the threads ... do i have to import any libraries (i have given class implements runnable )....but curiously it works fine in applet viewer....
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Okay, so if no errors are sent to the console then we have nothing to go on. The response at this point is probably something like:
"You have some environmental difference between the applet viewer and the the browser you are using to test in. Find the difference and fix it." Now, this difference is typically security, but it could be a lot of other things. These differences usually show you something in the Java console so if you aren't getting anything there then it indicates you have an error handling issue as well (you catch exceptions and do nothing with them, for example). So double check your error handling (and also double check that you are actually viewing the Java Console, it should display the version of the Java plugin you have as well as some commands you can give:

Java Plug-in 1.6.0_15
Using JRE version 1.6.0_15-b03-219 Java HotSpot(TM) Client VM
User home directory = /Users/Steve

Java Plug-in 1.6.0_15
Using JRE version 1.6.0_15-b03-219 Java HotSpot(TM) Client VM
User home directory = /Users/Steve


----------------------------------------------------
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
p: reload proxy configuration
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------

MRJ Plugin for Mac OS X v1.0.1
[starting up Java Applet Security @ Sun Sep 27 11:42:07 EDT 2009]
Sun Sep 27 11:42:08 EDT 2009 JEP creating applet Blink (http://java.sun.com/applets/jdk/1.4/demo/applets/Blink/)
Title: Blinker
Author: Arthur van Hoff
Displays multicolored blinking text.
<<< ProxyClassLoader: defined LiveConnectProxy class. >>>
<<< Here're the permissions you've got: >>>
<<< java.security.Permissions@e576d4 (
(java.net.SocketPermission java.sun.com connect,accept,resolve)
)
>>>


Another possibility is that you have a deadlock that occurs in your code which only expresses itself in the browser environment. So you would have to explore possible circumstances where that may happen and prevent it.

Beyond that simple advice we would need to see code. You could write up a small Small Compilable Example which shows the problem and we could test it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Implementing thread in an applet