Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with security error

Status
Not open for further replies.

ChrisMacPherson

Programmer
Jul 3, 2000
157
GB
Hi,
I am getting this error when trying to run a few different examples taken from the net which create simple applets and try to create a thread.

java.security.AccessControlException: access denied (java.lang.RuntimePermission modifyThreadGroup)


code is as below
Code:
private Thread th = null;
    public void start() {
        if (th == null) {
           
                 th = new Thread(this); << error hits here
            
            th.start();
        }
    }

I took these examples from good tutorials so am stumped why they dont work. Have also been searching for answers for ages so any help would be great.

I am running netbeans 4, j2se 1.5

Chris MacPherson


 
It's curious.

I suppose that the Security Manager fails at allocating the new thread on the current ThreadGroup.

I'd try instantiating a new Runnable object instead of this.

Cheers,

Dian
 
Here are some things to try:

If you're trying to do this in an applet, try doing it in an application instead. The permissions in a browser may be limited.

It seems to me that this construction will result in a loop that will consume all memory quickly. Since th isn't static, each time a new Thread is created, it has it's own copy of th that starts as null. Then when start() is called, th == null will trigger another Thread created. You may be getting an erroneous Exception simply because resources have been used up.

 
Thanks for your replies,

I have tried out some more applets and have been running in to the same message. If I try running an applet from a website in my browser it works. If I then download the source and try and run it in netbeans, then it come up with the error message in my first post.

Is this something to do with netbeans then I guess?

I am trying to learn java, this is really putting me off!

Chris MacPherson


 
The applet sandbox will not allow you to create new threads explicitly on the client machine, unless the applet is signed and has an appropriate security policy.

--------------------------------------------------
Free Database Connection Pooling Software
 
Thanks, that sounds like a pretty certain answer. So how do I go about doing that? The examples on the net that I was viewing did not mention anything about these issues. Any links to appropriate guides or tutorials would be greatly appreciated.

Chris MacPherson


 
Thanks sedj, I will try that out.

Initially I was trying to run my applet in the netbeans ide and was getting the errors, I tried to run it in my browser and it worked. I think I will forget the ide for the moment.

cheers again..


Chris MacPherson


 
Am I wrong or the default security policy allows and unsigned applet to create threads inside the same ThreadGroup as the applet?

Cheers,

Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top