What kind of java code is defined as one thread by JVM?

I know the definition of thread....
My teacher told me that normally, the java program run from the code from the first line to the end in order....
but somethimes, in main() method, the method does not run in sequence as I expected, and I thought that actually each method is 1 thread, but when I start using a method like finalize(), even sometimes the code inside it is also not in sequence....
so can any one help me on the question stated on my topic?
Secondly, can any one find any article or doc that tells me about the behavior of JVM on choosing the sequence of threads, so I know whether I should use thread method to set priority in need.....[/b[
thx

class Chair{
     public static int created = 0;
     public static boolean t = true;
     public int i;
     public Chair(){
          created++;
          i = created;
          //System.out.println(" i number is" + " " + i);
public void finalize(){
     if ( i > 10000){
          t = false;}
     System.out.println("Finalizing Chair object number: " + i + " .");
public class Garbage{
     public static void main(String args[]){
          System.out.println("Start finalizing 10 Chair objects");
          System.out.println();
          while(Chair.t){
               new Chair();
               /*if(Chair.i > 2000){
          Chair.t = false;
          /*for(int i = 0 ; i < 10000 ; i++){
               new Chair();
          /*Chair a = new Chair();
          a.Chair();     
}I was expecting that the JVM stops making Chair objects after Chair No 10000, but the result turns that JVM make more than 10000 objects.....

Similar Messages

  • What is the java equivalent to #define

    Hi,
    What would this declaration be in java:
    #define     STRAIGHT_FLUSH     1
    Many thanks, Ron

    There is no direct equivalent. As mentioned, enums can be used to fill one of #define's roles. (enumerated values)
    public static final constant member variables can fulfill another. (named constants)
    And actually, if I understand correctly, #define is not part of the C language per se, but belongs in the realm of the preprocessor, and you can run Java code through a c preprocessor.
    EDIT: Yeah, you can:
    :; cat X.java
    #define blah int
    public class X {
      Y y;
      blah x;
    jeff@shiro:/tmp 14:33:34
    :; cpp -P !$
    cpp -P X.java
    public class X {
      Y y;
      int x;
    }Message was edited by:
    jverd

  • What is this Java-code doing?

    I tried to find out what this part of a JAVA code is doing.
    I think that there are the two Strings 'target' and 'phrase'
    declared and initialized, however, what is the value of each
    of these two Strings then respectively what is the return value??
    Here youe see the code:
    1:....
    2: private String O00OoO0O0oOoo00O00oo(String target, String phrase)
    3: {
    4: for(; target.length() > phrase.length(); phrase += phrase);
    5: String s1 = "";
    6: for(int i = 0; i < target.length(); i++)
    7: s1 = s1 + "" + (char)((phrase.charAt(i) + target.charAt 8: (i)) - i);
    9:
    10: return s1;
    11: }
    thx for help!

    I wrote the following program :
    public static void{
    1: private String abcdefghabcdefgh(String target, String phrase)
    2: {  
    3: for(; target.length() > phrase.length(); phrase += phrase);
    4: String a = "";
    5: for(int i = 0; i < target.length(); i++)
    6: a = a + "" + (char)(target.charAt(i) - phrase.charAt(i) - i);
    7: System.out.println(a);
    8: return a;
    9: }
    10: String pass="xxxx";
    11: String ssap="oooo";
    12: String test = "";
    13: test = abcdefghabcdefgh(pass, ssap);
    14: System.out.println(test);
    15:}
    But I always got an error when I tried to compile it...
    and i tried to find out for hours a de5cription for this function...
    Actually I found the de5cription for String(String original) in the
    API documentation, and I think this is what I wrote in line 1...
    I tried so much versions so that this function would work...
    but it didn't at all. (Actually I think that I importet all the java classes
    I need). What the hell are I'm doing Wrong???!!!

  • What kind of Java questions can I ask?

    Here's a change:
    I want to interview some good java people. I have lots of Java questions in mind which I could ask them, however fellow JavaGuru's
    I would like some potential questions from you which I could ask someone who claims he/she is a good java programmer??
    I am asking because I want to be as fair as possible to the applicant and not ask them questions which I think are tough etc...

    Touchy subject.
    The language is not as important, as understanding programming concepts.
    So fine, when the programmer's horizont involves some abstraction levels.
    If a programmer can write an UML class diagram for a linked list.
    If a programmer knows a design pattern Singleton.
    If a programmer can write his/her own single linked list class with sorted insertion.
    Language concepts:
    - Why:
    import java.util.*;
    Map map = new HashMap();
    - Answer:
    Hiding the choice of implementation (HashMap) by using the more general
    interface Map.
    Don't expect much on an interview though. The situation might not be
    adequate to distinghuish between the good and the bad apples.
    Talking code is a good starting point, code of your making unfortunately.
    A good programmer will hesitate to show really useful code.
    A bad programmer might have stolen his/her code.
    The problem you might have, that you are in search of an expert, not
    having the expertise in-house. In that case you might get a better
    picture, talking about which IDE would be opportune, whether he/she
    has experience with the source version system CVS, what would his/her
    ideas be about coming projects.
    That would establish a common line of communication.

  • What kind of java monitoring tools are vailable for v1.4.2_11?

    Hi folks,
    I've spent a lot of time in the HPUX environment, but now I'm working in Solaris mostly. Unfortunately, we are having a problem with a java application that is hard to pin-point. Do you know of any Sun tools available to instrument, and or monitor a java application and tell us where it's spending most of it's CPU time? (or possibly how much of certain system calls it's running and spending time in?). We're running:
    ./java -version
    java version "1.4.2_11"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_11-b06)
    Java HotSpot(TM) Client VM (build 1.4.2_11-b06, mixed mode)
    In a nutshell, the problem is this....we run a java application in a VCS cluster, which just means that it has the potential to run on one of three possible systems. When the application is housed in a shared disk area that is moved to one particular server, then mounted. On one server, the java application runs 3x slower, but it pegs the cpu at 100%. On the other nodes, it runs at about 20% cpu, and it's out put is super fast. We have undergone an extremely detailed "ha" audit of the OS and cluster configurations, and we find that they are identical. (I used to design and consult with HP for their cluster implementations). I was able to gather some rudimentary OS statistics on java by running the "truss -cal -p <java pid>" command on both systems (good vs. bad). This revealed something strange: that on the bad system, nearly 90% of the system calls java made were "yield". On the good system, about .5% of the system calls were "yield".
    Other than that, I'm stumped. Now I'm looking for ways to instrument and monitor the JVM to help pinpoint what the JVM is doing..
    Any help is greatly appreciated.
    Thank you.
    Pete (PDQ)
    [email protected]

    There should be a working hprof on 1.4.
    http://java.sun.com/j2se/1.4.2/docs/guide/jvmpi/jvmpi.html#hprof

  • Which kind of Java do I need?

    I've programmed in java before, but mainly just console programs and small applets. Now I need to do something meaningful. I need to create a massive program for a restaurant and figured it should be done in java so the code would be transferable between multiple platforms, as it will contain lots of graphics. My question is, what kind of java do I code it for? There will be intense networking in it, but it's not an applet, rather just a program that can run on top of windows, or linux, or whatever os it is used on, provided we have the correct java package installed for the given os. I saw Java API, servlet, and a whole collection of other styles of java. I'll need to be able to do graphics with mouse functions, writing files accross a network, and printing accross a network for the most part. It will use a touchscreen in the end that will emulate mouse functions. Does anyone have any ideas as to what I'm talking about and what I might need? Does anyone have any suggestions for books I should look at?

    I'm going to assume that your writing a point-of-sale system, and that you'll have check-out points, and stations for waitress to create checks. Please correct me if i'm wrong.
    Anyhow, I'm lazy and cheap. I'd use J2SE to write 3 programs -- 1 console program and 2 gui programs.
    the console program will be a Server. This will be the program to which all your other programs will connect to so that all your data will be in once place (i.e. a waitress can create a check at a station, and the
    check will be avaliable on the server so that you can retrieve it at a check-out point)
    Note: the server should be a console program to reduce overhead. (i.e. no wasted time on useless graphics)
    The two gui programs would be:
    1) A program for creating/modifying checks for waitresses to use
    2) A program to "clear" or bill for a check (next to the cash register)
    Both programs would connect to the console server program.
    If you use a database (which you definantly should!) you could
    also write a program to generate reports baised on data you collect
    from the waitress stations and the cash register (i.e. # of people who
    walked out on checks, highest/lowest selling food, most profitable
    food, busiest/slowest times of the day, etc.)
    Lets hope I'm not wrong!
    --Dave

  • Java code changes deletes when saving webdynpro project

    hi guys,
    is it always necessary to create methods from wizards in the webdynpro view controller??? other wise if I am already in the code and create some new method which is not created by wizard, it is removed once I am going to save the changes in the java code.
    Can any one tell me what should I do??
    Regards,
    Naeem

    hi,
    you can try to print some message on the screen, if you dont know how to debug.
    or you go with [https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/849170e3-0601-0010-d59e-ddfce735fac5|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/849170e3-0601-0010-d59e-ddfce735fac5]
    Best regards,
    john

  • What kind of design pattern is this?

    Hi ,
    I am just learning the designpattern. So when I went through different kinds of design pattern, I got some doubts as it looks same some design patterns. could anybody please tell what kind of design pattern is the following one?
    public interface IExporter{
         void export();
    public class ExcelExporter implements IExporter{
    public void export(){
    //TODO implementation
    public class CVSExporter implements IExporter{
    public void export(){
    //TODO implementation
    }thanks in advance..

    Well - in structure, it is nearest to the Command pattern as far as I can tellOr Strategy. Or Builder. Several design pattenrs may share the same class structure, the difference is in the context, forces, and the parts one want to be flexible. And if someone wants to make it explicit which pattern is applied, they should name things accordingly.
    As Saish said this example shows little more that inheritance at work. Not a pattern in itself, but a core element of the language. Trying to "identify" a pattern that is not obvious from the context is either:
    - a sign that the original coder completely missed the point of using a pattern (which is, as Saish said too, assentially about communication)
    - a sign that the maintenance coder is looking for patterns where there aren't
    - an exercise question
    but it differs in so much as its motivation is to polymorphically allow the use of different exporters rather than provide a set of action commands.That shouldn't count as a difference, merely as an "application" (it's perfectly valid to have a hierarchy of commands all devoted to exporting, although, as stated, if the original coder applied the Command pattern, he should have made it explicit, by renaming the interface, e.g. to ExportCommand).

  • What kind of codes are those????

    i found some codes i put in a java game chatroom like: m.msg_self and in the chat appears :talking to yourself is a sign of ....! what kind of codes are those and where do i find more?

    They are user-defined codes depending on the application.

  • Adding rows to J2ME WTK/Settings/User Defined (through Java code)

    Hi all..
    Just a quick question..
    Is it possible to add Key/Value pairs to a MIDlet's 'User Defined' field through Java code..(ie) - add a new row to the User Defined field..
    If not, can anyone tell me how a Bluetooth-Client GUI can save an image it has been sent by a Bluetooth-Server GUI?
    Thanks in advance..
    Rookie

    if i understand you, you want to call application module method when user clicks on add button on the UI and your table is from VO
    so what i can come up for now is:
    1) create variable binding from the iterator for both name and price.
    2) on your UI action button :
    <af:commandButton actionListener="yourbean.addToCart">
    <f:attribute name="pName" value ="binding.<created name bind variable>"
    <f:attribute name="pPrice" value = "binding.<created price bind variable>"
    </af:commandButton>
    3) custom Managed Bean:
    //yourBean.java
    public void addToCart(ActionEvent e){
    // get binding here
    // use executeWitParams method to send parameter to the function "testMethod" and execute
    //AppModuleImp.java
    public void testMethod(String pName,String pPrice) {
    CardVOImpl vo = this.getCartVO1();
    CardVORowImpl r = (CardVORowImpl)vo.createRow();
    r.setAttribute("NAME", pName);
    r.setAttribute("PRICE", pPrice);
    vo.insertRow(r);
    Hope this helps...
    Let me know if not..
    Thanks
    Edited by: MavenDev on Oct 30, 2011 8:08 PM

  • What kind of code signing certificate do I need for Profile Manager?

    I'm new to Lion Server and the Profile Manager, and I'm wondering what kind of CA-recognized code signing certificate I would need to buy to use in the Profile Manager -> Sign configuration profiles? For example, Verisign sells a bunch of different kind (http://www.verisign.com/code-signing/): Microsoft Authenticode, Java, etc.
    Patrick

    The cable should be just the normal one, the special smarts that tell the tablet to charge at full speed is in the power brick.

  • How to provide value to a User Defined field thru java code

    I am using OIM 11.1.1.5.
    I have a user defined field called Unique-Customer-Number. This field need to be pre-populated during user creation (using OIM Web UI) and the value comes from a java code.
    Can any of you tell me the high level steps to implement this.
    Thanks!
    Kabi

    Thanks Rajiv,
    I just followed everything on metalink 1262803.1. My console shows the followings during Metadata import.
    weblogicImportMetadata.bat :-
    Starting import metadata script ....
    Please enter your username :weblogic
    Please enter your password :
    Please enter your server URL [t3://localhost:7001] :t3://10.10.99.99:7001
    Connecting to t3://10.10.99.99:7001 with userid weblogic ...
    Successfully connected to Admin Server 'adm_server01' that belongs to domain 'server01'.
    Warning: An insecure protocol was used to connect to the server. To ensure on-the-wire security, the SSL port or Admin port should be used instead.
    Location changed to domainRuntime tree. This is a read-only tree with DomainMBean as the root.For more help, use help(domainRuntime)
    Disconnected from weblogic server: adm_eimsdv1s01
    End of importing metadata script ...
    Exiting WebLogic Scripting Tool.
    How I will I know that my plugin/ event-Handler is registered successfully. Is there any screen where I can see all registered plugins ?

  • What kind of cell library does opensparc T1 verilog code use?

    Hi all
    I am running simulations on the instruction fetching unit module of opensparc T1 recently, when I tried to simulate the module with VCS from (synopsys), it has some errors below
    Error-[URMI] Instances with unresolved modules remain in the design.
    Invalid instantiation at: "sparc_ifu_fcl.v", 1022: dffrl_async rstff(
    .din(grst_l), .q(fcl_reset_l), .clk(clk), .se(se),
    .rst_l(arst_l));
    Invalid instantiation at: "sparc_ifu_fcl.v", 1035: dff_s #(4) real_reg(
    .din(lsu_ifu_addr_real_l), .q(itlb_addr_real_l), .clk(clk),
    .se(se));
    Invalid instantiation at: "sparc_ifu_fcl.v", 1051: dff_s #(4) xlate_reg(
    .din(xlate_en), .q(xlate_en_d1), .clk(clk), .se(se));
    Invalid instantiation at: "sparc_ifu_fcl.v", 1077: mux3ds creal_mx(
    .dout(fcl_itlb_cam_real_bf), .in0(sw_itlb_real),
    .in1(this_itlb_real), .in2(tlu_fc ...
    It seems like some modules like mux3ds or dff_s #(4), I am using NangateOpenCellLibrary_PDKv1_3_v2009_07/verilog/NangateOpenCellLibrary_typical_conditional.v as library files.
    But it does not hve descriptions to modules like mux3ds or dff_s #(4).
    Does anyone know what kind of cell library that opensparc T1 use to define those modules?

    oh also - to show (for coherence) what happens if i try to
    modify it
    i can add "import ,,, ack let me add something else here
    hmm....
    static function blank() { trace("screens off!"); screensaver.blank("SCREEN_1"); }
    okay THAT is where , aside from hitting a catch - that it gives errors (getting about 50 errors, every single reference in the file)
    now note - the other class/actionscript file right next to it doesnt throw any errors at all - very very similar - nothing wrong with it
    now if i put "import screensaver;" directly above that line
    it lists the exact same errors + one more error, in the same way
    if i put that line upwards more, same thing
    it can not find the include componentry or whatever it is called
    i can import 20 things there and it wont go anywhere, no way, no how
    now if i put the "import screensaver" alllllll the way at the top prior to the package { } declaration
    then! i get a different error, cant put the import statement there
    otherwise it's boffing on every single thing in the file - and note - not any of the other three files that are very similar
    so basically to further elucidate - i am getting the actual import statement to fail

  • What is wrong in this java code?

    Can someone please tell me what is wrong in this java code?
    /* The program is intended to start animating text at the click of a button, pause it at another click and resume at the next click. It should continue like this */
    import javax.swing.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    public class TextAnime implements Runnable
    JFrame frame;
    boolean flag;
    Thread animeThread;
    JLabel label;
    String[] textArray;
    public TextAnime()
    flag = false;
    animeThread = new Thread(this);
    frame = new JFrame("Animate Text");
    GridBagLayout gbl = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    frame.setLayout(gbl);
    JButton button = new JButton("Start");
    label = new JLabel("Stopped");
    textArray = new String[5];
    String textArray1[] = {"Programmer", "SportsMan", "Genius", "Friend", "Knowledgable"};
    for(int ctr = 0; ctr<5 ; ctr++)
    textArray[ctr] = textArray1[ctr];
    gbc.weightx = 1;
    gbc.gridx = 0;
    gbl.setConstraints(button,gbc);
    frame.getContentPane().add(button);
    ButList bl = new ButList();
    button.addActionListener(bl);
    gbc.gridx = 1;
    gbl.setConstraints(label,gbc);
    frame.getContentPane().add(label);
    frame.setSize(200,150);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    frame.setVisible(true);
    public class ButList implements ActionListener
    public void actionPerformed(ActionEvent evt)
    if(flag == false)
    flag = true;
    animeStart();
    else
    flag = false;
    //animeStop();
    public synchronized void animeStart()
    animeThread.start();
    Thread newThread;
    newThread = Thread.currentThread();
    newThread.notify();
    public void animeStop()
    animeThread.interrupt();
    public void run()
    int i = 0;
    try
    while(i == i)
    if(i==5)
    i=0;
    label.setText(textArray);
    animeThread.sleep(1000);
    i++;
    if (flag == false)
    animeThread.wait();
    catch(InterruptedException ie)
    label.setText("Stopped");
    public static void main(String args[])
    TextAnime ta = new TextAnime();
    Please tell me if this can be written in a more simpler manner. Also please correct this code. I am tired after trying many times.

    When I fix your error, compile and run it, I get this exception:
    Exception in thread "AWT-EventQueue-0" java.lang.IllegalMonitorStateException
         at java.lang.Object.notify(Native Method)
         at cruft.TextAnime.animeStart(TextAnime.java:81)
         at cruft.TextAnime$ButList.actionPerformed(TextAnime.java:63)
         at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
         at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
         at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
         at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
         at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
         at java.awt.Component.processMouseEvent(Component.java:6038)
         at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
         at java.awt.Component.processEvent(Component.java:5803)
         at java.awt.Container.processEvent(Container.java:2058)
         at java.awt.Component.dispatchEventImpl(Component.java:4410)
         at java.awt.Container.dispatchEventImpl(Container.java:2116)
         at java.awt.Component.dispatchEvent(Component.java:4240)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
         at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
         at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
         at java.awt.Container.dispatchEventImpl(Container.java:2102)
         at java.awt.Window.dispatchEventImpl(Window.java:2429)
         at java.awt.Component.dispatchEvent(Component.java:4240)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
         at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
    %

  • What kind of Cellphone supports for Web Services in Java Application?

    I have developed a software in J2ME integrated with Web Services!
    I am wondering what kind of Cellphone (Nokia, Samsung, ...) supported Web Services now?
    Any help is appreciate!

    Hi Shannon,
    The type of proxy I'm familiar with is at the http connection level and
    associated with the networking properties in the JDK, See:
    http://java.sun.com/j2se/1.4.2/docs/guide/net/properties.html
    Your question may be related to JWS proxies, See:
    http://edocs.bea.com/workshop/docs81/doc/en/workshop/guide/howdoi/howUseTheJavaProxyForAWebService.html
    You may want to ask this question in the workshop newsgroup.
    Hope this helps,
    Bruce
    shannon lee wrote:
    >
    Hi, all;
    I try to find out how the java proxy of web service in weblogic server 8.1
    works. Suppose I use the java Proxy of a WebSerice in a client application whatever
    whithin or outside the application of the web service, does the proxy actually:
    1. translate my java arguments objects in XML to create SOAP msg,
    2. then send the msg across the network, and web service also response SOAP msg,
    3. then proxy translate it into return value of the method call ?
    If that is true , the Java Proxy seems very inefficient, right?
    Can any body tell me how the proxy works ?
    regards,
    shannon

Maybe you are looking for

  • Where are power options saved in the Windows registry?

    The problem is that a customer IT department did something wrong during deploying GP preferences. Now nothing is working and we have to delete all settings, that the new GP preferences I newly created will work. Now GP preferences is not working on 3

  • In iphoto i could export direct to flickr and facebook is it possible to this in photos ?

    in iphoto i could export from the application to flickr and facebook i cant seem to do this in photos also where is the straighten button in edit ?

  • Object cast - J2EE to ActionScript strange problem

    Hello, I am working in a project with multiple layers composed by Flash+Flex; BlazeDS; J2EE+Hibernate. I have some services to get all the data from database and I have a strange problem when I try to cast some objects from J2EE to ActionScript via B

  • Split Panes, Frame and Resizing

    Hi, my user interface is made up of a message panel using the created class SplitPanes2 through the method createSplitPanes called from a class that extends Frame. (will post code if required: lengthy). When the frame is resized/maximized, the splitP

  • Ios 5.1.1 downloads but does not update on itouch

    When I received the notification that I needed to update my operation system to ios 5.1.1, I clicked the "download and install" button.  The ios takes an hour or so to download so I usually walk away and do something else. (This has happened twice).