Is thread still active after main method exits?
Hi All,
Yesterday we were discussing. wether it is possible for a thread to be active even after the main method, from which it was spawned, exits.
any comments?
Hello,
If you start a thread from the main() method and then return from main(), the thread will remain running. Just try it out:
public class Test
implements Runnable
public static void main(String[] args)
Thread t = new Thread(new Test());
t.start();
System.out.println("Returning from main()");
public void run()
try
Thread.sleep(5000); // Wait for 5 seconds
System.out.println("Hello, I'm still here!");
catch (InterruptedException ie)
ie.printStackTrace();
}Note: If you exit main() using System.exit(), all threads will be killed!
Jesper
Similar Messages
-
Season Pass - Still active after the season is completed
Some time ago I purchased a pass for the first season of Breaking Bad.
After seven episodes the season was officially over.
However, the season pass remains active (it still is).
When I want to switch to a different iTunes store (different counry), iTunes tells me that it is not possible as long as I have active season passes.
Is a season pass supposed to expire/end automatically after the respective season is complete?
If it is supposed to be this way, how can I close/end my still active season pass.
Thank in advance for the helpHi Girish,
My bad, forgot to put all the required info in the post. Sorry about that.
Database 10.2.0.2.0 - enterprise, Linux OS. I have enough SGA (64gb), PGA, undo, temp tablespace space.
The select is a "normal" read only select that needs to read millions of blocks from data files. The main table is partitioned and the waits are on reading data from partitions. In v$session the main session and the child processes are marked as killed.
In v$lock I see that the wait is on db read scan. Everything is working. That's actually my issue.
Why it's still querying data/reading from disk when I killed all the sessions.
Doesn't Oracle stop the processes associated with a killed session?
I killed the session: alter system kill session 'sid,serial';
Do you think "alter system disconnect session 'sid,serial' immediate" is better?
What I don't understand is how can I stop fast (ok I get that it can not happen in a few seconds) a query that is only read only that is running for too long. When I kill a session I was expecting the processes associated with it to stop. In a update/insert/delete, the server will wait for the rollback, but this is not changing data.
If you think more debug is necessary I will upload on Monday AWR and all the statistics I collected. I am not in the office now.
Thanks,
Daniel -
Question of the day: In which Thread context does the main method run ?
let's say, you create a JFrame in the main method:
public static void main(String[] args)
new MyJFrame();
let's suppose, you construct the whole JFrame
inside the constructor, which contains a lot
of other Swing components, like JTree's and more.
AND the JFrame calls setVisible(true) in its
constructor.
-> According to my knowledge, this won't work
properly - it will function, BUT you will get one
or two quite big exceptions (which usually start
with a nullpointer exception, produced by the
PLAF, but the whole stacktrace shows, that the
the exception was thrown AND catched inside
the Swing objects.
Reason for this would be, that all operations
after the "setVisible(true)" statement must be
carried out in the eventdispatch thread, according
to Swing rules.
Now, as you can see by running the source below,
the main() method always is processed in special thread,
NOT the event dispatch thread - which produces the above behaviour.
My Question:
Wouldn't it have been easier to let the JVM
process the main() methods right in the
event dispatch thread ?
Or:
Why is the JVM designed to process the
main() method in a special thread and not
the Swing event dispatch thread ?
opinions?
Regards
JPlaz / SnowRaver
package Test1;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Frame1 extends JFrame
public Frame1( final String title, int position )
this.setSize(400,300);
this.setLocation(position,position);
this.setVisible(true);
if( SwingUtilities.isEventDispatchThread() )
System.out.println("Constructor of "+title+" is processed IN the event dispatch thread.");
else
System.out.println("Constructor of "+title+" is processed in ANOTHER than the event dispatch thread.");
public static void main(String[] args)
// First creation just from the startup thread context :
new Frame1("first Frame", 60);
// Now we let the second creation be done in the
// eventdispatch thread context for sure :
SwingUtilities.invokeLater( new Runnable()
public void run()
new Frame1("second Frame",120);Matt,
it's been so long, I don't have the full answer in my head.
This page on Adobe.com has an example that shows Flash 4
mouse stuff (I'm Mr
Vague today) when you scroll down. Your timelinme reference
will be
something like
TellTarget(_Root, gotoAndPlay(50))
Hopefully from that vagueness you can locate the right
answer.
Steve
Adobe Community Expert: Authorware, Flash Mobile and Devices
My blog -
http://stevehoward.blogspot.com/
Authorware tips -
http://www.tomorrows-key.com -
Why is inventory count Doc's status still active after posting difference
Thanks,
LindaSounds like inventory management.. I found document is still active through MI02 after I am done with posting difference through MI20.
Here is what I did,
MI31 create inventory count sheet (100000207)for warehouse
M104 Enter inventory count
Mi11 recount for some items in 100000207
Mi20 post difference
Question: why 100000207 is still active since I alreay completed posting difference? Now the only option I have to deactive is to delete it, however when I am trying to do so, system give me a warning sign saying deletion will errase the evidence to posting difference. Is there any steps I missed so 10000207 is still active?
thanks,
Linda
Edited by: LindaSAP on Dec 2, 2009 5:00 PM -
Why is the icon for syncing still active after disconnecting?
My phone got stuck on step 6 when I updated and backed up my files during iOS 7 upgrade. I tried to cancel and start over but it was still stuck on trying to transfer music. As far as I can tell, I still have all the music I want on my phone. The icon to disconnect is still active on my home screen. Why does it keep doing that? Is it an indication it's not finished sync in or that it's always syncing through a wi-fi connection? I'm already on the iOS 7 platform.
My phone got stuck on step 6 when I updated and backed up my files during iOS 7 upgrade. I tried to cancel and start over but it was still stuck on trying to transfer music. As far as I can tell, I still have all the music I want on my phone. The icon to disconnect is still active on my home screen. Why does it keep doing that? Is it an indication it's not finished sync in or that it's always syncing through a wi-fi connection? I'm already on the iOS 7 platform.
-
Cisco AnyConnect's Firewall is still active after I uninstalled the program
Hi,
i used the client to access my university network from home. But since this isn't necessary anymore I uninstalled the Cisco AnyConnect
Secure Mobility Client. But the Firewall of it is still active. How can i disable it?
I just don't know where to find the rule for the firewall.
RegardsHello Peter,
You want to disable the possibility to connect via anyconnect to the firewall,
Disable the webvpn functionality
webvn
no enable outside
Regards -
GPS still active after turning it off
The gps works good, few seconds to fix the location but when I turn it off the gps still runs in background eating the juice... The toggle is turned off but if I check the battery life I always see the gps alive!
How to solve, except rebboting the phone everytime??
Topic edited by RickardUsually even if you take the tick out of "GPS Satellites", google apps still can access the gps if you had granted it permission, the best way to completely stop GPS is to go to Settings>Location Services and turn off "Access to my location" this will completely shut down GPS from everything. Just restart the phone after that and check if that solved your problem
-
Email account still active after account closed
In November 2011 I canceled my DSL subscription. To this day I still receive email in my Verizon.net account. I would like to have this account terminated. How can I accomplish this ? I have no online access to the verizon.net email portal being that I canceled but I can still receive email via Outlook.
Hi and Welcome to the Community!
Only your carrier and BB have access to the necessary systems to see what is happening and correct it. From what you describe, there is nothing you (as an end user) can do...only someone at the system can do anything about it.
Good luck!
Occam's Razor nearly always applies when troubleshooting technology issues!
If anyone has been helpful to you, please show your appreciation by clicking the button inside of their post. Please click here and read, along with the threads to which it links, for helpful information to guide you as you proceed. I always recommend that you treat your BlackBerry like any other computing device, including using a regular backup schedule...click here for an article with instructions.
Join our BBM Channels
BSCF General Channel
PIN: C0001B7B4 Display/Scan Bar Code
Knowledge Base Updates
PIN: C0005A9AA Display/Scan Bar Code -
Re: Email account still active after account closed
bump
Hi there!
There are two sets of credentials to discuss...and I can't tell for sure which you are referring to, so I'll cover both...
BIS Credentials -- BIS is the service, controlled by your carrier, that functions as the conduit between your email services (e.g., Yahoo, Gmail, etc.) and your BB. BIS has separate credentials of it's own, and stores the credentials for all of the email accounts that you configure. The ID/PWD can be whatever you want them to be.
Email Credentials -- these are your email services (e.g., Yahoo, GMail) and they each have their own credentials. These credentials are what is stored inside of your BIS account.
So, from what you said, it sounds like you changed, at your email server, your email credentials and you need to therefore change what you have stored inside of BIS, but you are unable to log into BIS to do so. Is that correct?
If so, you need to contact your carrier -- they control your BIS account, including the credentials that you created sometime in the past.
Good luck and let us know!
Occam's Razor nearly always applies when troubleshooting technology issues!
If anyone has been helpful to you, please show your appreciation by clicking the button inside of their post. Please click here and read, along with the threads to which it links, for helpful information to guide you as you proceed. I always recommend that you treat your BlackBerry like any other computing device, including using a regular backup schedule...click here for an article with instructions.
Join our BBM Channels
BSCF General Channel
PIN: C0001B7B4 Display/Scan Bar Code
Knowledge Base Updates
PIN: C0005A9AA Display/Scan Bar Code -
I have a PowerBook G4 that I would like to use exclusively for my online banking. It may be infected with the Flashback malware virus. If I disable Java, will this effectively block the malware? Or must I completely remove the malware from my computer?
You need to remove the malware. Java is only used to inject the code.
I didn't think the flashback stuff was for G4's.
But if it was, first look in your ~/Library/LaunchAgents since that was one of the more common injection points (not the only one).
Look here for a cookbook of some other places to look. -
When does the Java main(String args[]) method exit?
Hi all,
I and my colleagues want to know, when does the main() method exit?
we wrote a small code as follows:
import java.awt.*;
public class Test {
public static void main(String[] args) {
Frame f = new Frame("hi");
f.show();
System.out.println("after show");
and ran the program, in which case I could see the printed message "after show", but although there is no code after the System.out.println(), the Java virtual machine does not exit and waits for the Frame to close.
My question is has the main method exited in this case? since it clearly shows that it does not have any more code to execute. Does java create the main method as a thread or as a process?
regards,
HarshadTo make your application terminate you need to add code to cause the AWT thread to handle the termination. In your code, before f.show(), try:
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
public void windowClosed(WindowEvent e) {
System.exit(0);
});Now, at least you can click on the little "X" on the upper right-hand corner of the Frame (at least in Win95/98/NT) environments) to cause your application to receive a window closing event. It is also possible to add a menu with an option to exit; in that case I'd use an EventQueue to cause a window closing event to be sent. -
Concurrency exit, thread still running.
Hi all,
I am experimenting with Java SE 5 concurrency framework.
import java.io.IOException;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;
public class ConcurrencyDemo {
/** Creates a new instance of ConcurrencyDemo */
public ConcurrencyDemo() {
FutureTask ft = new FutureTask<MyCallable>(new MyCallable());
ExecutorService es = Executors.newSingleThreadScheduledExecutor();
int i = 0;
while(i++ < 10) {
es.submit(ft);
//es.submit(ft);
try {
double d = ((Double)ft.get()).doubleValue();
System.out.println(d);
} catch(Exception e) {
System.err.println(e);
System.out.println(ft.isDone());
class MyCallable implements Callable {
public Double call() throws IOException {
return Math.random();
public static void main(String bicycle[]) {
calleeMethod();
private static void calleeMethod() {
ConcurrencyDemo cd = new ConcurrencyDemo();
}After executing the main in debug (in eclipse), i see two threads still running after F8,
Thread [pool-1-thread-1] (Running)
Thread [DestroyJavaVM] (Running)
Why the program is not exiting? Any idea?
Thanks,
NiravI think the process (javaw.exe) should have been terminated but i see:
ConcurrencyDemo [Java Application]
ConcurrencyDemo at localhost:4509
Thread [pool-1-thread-1] (Running)
Thread [DestroyJavaVM] (Running)
C:\Program Files\Java\jre1.5.0_01\bin\javaw.exe
in debug pane in eclipse. -
When I exit FF then later try to go back to it, i get message that it is still active and i must exit (no xxcan do) or restart pc..
== This happened ==
Every time Firefox opened
== don't know as three people use pc, could have starteed after windows update 2 months agoSee http://kb.mozillazine.org/Firefox_hangs and [[Firefox hangs]] (Hang at exit)
-
How to notify() the main method in the given code snippet
consider the given code snippet
code
public class WaitTest {
public static void main(String [] args) {
System.out.print("1 ") ;
synchronized(args) {
System.out.print("2 " ) ;
try {
args.wait();
catch(InterruptedException e){}
System.out.print("3 ");
code
Here since there are no threads to notify the main()method the statement System.out.print("3 "); never gets executed.And i cannot use the non static notify() from a static context.In this case how will I notify the main() method.A thread can only do one thing at a time.
It cannot be waiting and notifying at the same time.
notify only works if another thread is waiting.
wait() only stops if another thread notify/notifyAll() it at the same time. -
Object life in main method after frame created
hi
i'm having a slight problem with the life of an object i'm creating in the main method of my application.
i have a JDesktopPane that is initialised in the main class's main method and constructor. within the main method i also add the first internal frame to the desktop.
after the user completes the details of the first frame, another is called (from this first frame) and the first frame is disposed.
the problem is that although all subsequent internal frames added to the desktop outside the main class, they are garbage collected with no problems (i'm using a profiler), however the first frame and the frame created from that first frame are never collected due to the reference maintained in the main class. i've tried adding the creation of these frames outside the main class but given that these methods are called from main the reference is still maintained.
is there any way to create those first 2 frames without the reference being maintained in the main class such that they become elegible for garbage collection? do i have it all wrong perhaps and my approach is bad?? any help would be greatly appreciated.
thanks heaps.
Takishi
thanks for your reply.
i tried that and it didn't work. the instance of that first internal frame is still there.
i really am at a loss with this one.
any other suggestions would be greatly appreciated.
Takis
Maybe you are looking for
-
How can I get the alarm to sound on my Iphone with ios7
I set two different alarms on my phone, and I never had a problem hearing them until I updated to IOS7. I wake up late and can see the notification and snooze option, but no sound. Can anyone help?
-
I see most recent file is called sql server log shipping work file
What is "SQL server log shipping work file"?
-
Deployement Error In Netweaver Application Server
Hi, When i try to deploy j2ee applicaiont its throwing the below error. "Cannot deploy application sap.com/SAP eTrans. Reason: Error during reading manifest file.nested exceptionis: java.rmi.RemoteException:com.sap.engine.services.library_container.d
-
Hi, I have downloaded an Excel file from my internet bank, but it won't open in Numbers. I get this error message: Import Warning - This is a HTML document, not a valid Excel document. The data might look different. It opens fine in Excel on my PC th
-
InfoType 0001 in Employee respoitory
I cannot see infotype 0001 in the Employee repository in MDM ? Does anyone knows why ? How will we be able to map Jobs, Positions, Org Units, Qualifications etc ?