termination of program on main thread exit?

I have two threads: the main thread and a thread generated from the main thread.

When the main thread exits, will the whole program terminate?



Java programs terminate when all non-daemon threads finish.

The documentation states:

When a Java Virtual Machine starts up,
there is usually a single non-daemon
thread (which typically calls the
method named main of some designated
class). The Java Virtual Machine
continues to execute threads until
either of the following occurs:

  • The exit method of class Runtime has been called and the
    security manager has permitted the
    exit operation to take place.
  • All threads that are not daemon threads have died, either by returning
    from the call to the run method or
    by throwing an exception that
    propagates beyond the run method.

If you don’t want the runtime to wait for a thread, call the setDaemon method.


Load javascript before rendering page?

I want to run some jquery code before my page have loaded. Im adding some classes which are changing the css with javascript, and when the page loads i see the “old” css for a short time. Any ideas? Thanks


I want to run some jquery code before my page have loaded.

This is easily done; it’s funny because much of the time, people are trying to do it the other way around.

When the browser encounters a script tag, barring your using a couple of special attributes (and the browser supporting them), all processing of the page comes to a screeching halt and the browser hands the script to the JavaScript engine. Only when the script completes does processing of the page continue.

So if you have a script tag in the head section of your page, you can output CSS classes via the document.write function:

<DOCTYPE html>
<script src='jquery.js'></script>
if (some_condition) {
    document.write("<style>foo { color: blue; }</style>");
else {
    document.write("<style>foo { color: red; }</style>");

Note that some_condition in the above can only rely on, and refer to, the items above it in the document (since the browser hasn’t done anything with the rest of the document yet, as it’s waiting to see what document.write content the script is going to output).

Live example (refresh it a few times, half the time it’s red, half the time it’s blue). It doesn’t use jQuery, but you get the idea.


Invalid file name error in Eclipse

I often encounter the following error:

resdrawablemy-image-48.png: Invalid file name: must contain only [a-z0-9_.]

My file name is “my-image-48.png” which seems to conform to the constraints listed in the error.

What am I missing?


you cannot use the dash -, you only can use letters (from a to z), numbers (0 from 9) and underscores _ So you should replace “-” by underscores.


Chrome Extension: Open tab without popup

I’ve used the following code in my popup.html file:

<script type="text/javascript" charset="utf-8">
    chrome.tabs.create({'url': chrome.extension.getURL('page.html')}, function(tab) {

When I click the extension icon a new page does open, but so does an empty browser popup near the button. How do I open the tab without the empty popup appearing?



Popup is optional. Just remove default_popup property from your manifest and then you can listen to icon click events in a background page or event page:

chrome.browserAction.onClicked.addListener(function(tab) {
        'url': chrome.extension.getURL('page.html')
    }, function(tab) {


How do you enable a disabled radio button using jquery in ie7

This works in Firefox. How can I make it work in IE7?

$( '#addressSection input:radio' ).attr( 'disabled', false );

I’ve also tried these to no avail:

$( '#addressSection input:radio' ).removeAttr( "disabled" );

$( '#addressSection input:radio' ).attr( 'disabled', 'false' );

$( '#addressSection input:radio' ).attr( {disabled: false} );

$( '#addressSection input:radio' ).attr( {disabled: 'false'} );

Here’s the radio button html as it is rendered by IE7. The original is written in Spring and custom tags.

<div id="addressSection">
  <div class="column">
    <ul class="simpleForm">
        <input id="addressUseUorA" name="addressUseUorA" value="U" type="radio" type="text" value=""/>
        <label for="addressUseUorA">Use User Address</label>
        <input id="addressUseUorA" name="addressUseUorA" value="A" type="radio" type="text" value=""/>
        <label for="addressUseUorA">Use Account Address</label>


Here’s what was causing the issue.

I disabled the field like this, trying to disable all fields in the DIV:

$( '#addressSection' ).attr( 'disabled', true);

This causes an issue in ie7, but not firefox.

The issue was resolved when I changed the disable code to:

$( '#addressSection input' ).attr( 'disabled', true);

my guess is that the disable attribute was applied to the div and not the field and so could not be removed by referencing the radio button.

Thanks for all of the help.


did you try:

$( '#addressSection input[type="radio"]' ).removeAttr( "disabled" );
Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..