List in thread..

hi All,
i'm new with thread. so i just starting with the simple program like:
class thread1 implements Runnable{
     private String name;
     public thread1(String nameThread){
          name = new String(nameThread);
     public void run(){
          System.out.println(name+" was sleeping");
           System.out.println(name+" wake up");
class thread{
     public static void main(String[] args){
          Thread student = new Thread(new thread1("student"));
          Thread kid = new Thread(new thread1("kid"));
          Thread sherlock  = new Thread(new thread1("sherlock"));
          student.start();
          kid.start();
          sherlock.start();
}and output:
student was sleeping
kid was sleeping
sherlock was sleeping
student wake up
kid wake up
sherlock wake up
after that, i'm trying to modify this code that create thread automatically depend on element in list but the i still want output was same. so, this my code.
class thread1 implements Runnable{
     private String name[] = {"Student", "kid", "sherlock"} ;
     java.util.List threads = new java.util.ArrayList(Arrays.asList(name));
     public thread1(String name[]){
          this.name = name;
     public void run(){
          for(int i=0; i<2; i++){
          System.out.println(name[i]+" was sleeping");
           System.out.println(name[i]+" wake up");
class thread{
     public static void main(String[] args){
          int T=100;
          String name[] = new String[T];
          Runnable r = new thread1(name);
          Thread t = new Thread(r);
          t.start();
}but the output is:
null was sleeping
null wake up
null was sleeping
null wake up
so, what the problem with my code. hope can anybody give any solution.
thanks.

problem is in your second program you have a private string array names name and that is initialized to a array or nont null strings. But the constructor accepts a string array argument and replace the name with the value of that argument. As a result initialising the name array with the declaration is pointless.
And when you creating a thread1 instance you pass a 'new String[T]' to the constructor which will be assigned to the name array in the thread1 class. But that argument is an uninitialized array which has 100 null elements.

Similar Messages

  • When moving from a list of threads view to a thread would be nice to jump to last thread read.

    When moving from a list of threads being viewed to a thread, it would be nice to jump to last thread read or first unread thread.
    Sometimes the threads get rather long.  Sometimes I haven't read a thread in awhile & I forget where I have left off reading a thread. It would be nice to have an icon to click on to move to your last read post or the first non-read post. 
    Seems this could be implemented in javascript without too much problem.  Might be a problem of when to get rid of the tracking data.
    Robert

    This would be a new capability.   I didn't know you could jump directly to the last post in a thread by clicking on the posters name in your discussions.  However, I am interested in jumping to the first post that I haven't read.
    Since writing my original post, I realize that software doesn't know what posts I have read. Lets say there are are 26 posts in a thread.  Lets assume these are divided into three pages with at most 10 items in a page:
    page 1 -- a, b, c, d, e, f, g, h, i, j
    page 2 -- k, l, m, n, o, p, q, r, s, t
    page 3 -- u, v, w, x, y, z
    The software know that I have viewed the first three pages.  It doesn't know what post on the pages I have read.  The software would need to assume I have read all the available posts on a page.
    Now lets assume that 12 more post were added.  This results in:
    page 1 -- a, b, c, d, e, f, g, h, i, j
    page 2 -- k, l, m, n, o, p, q, r, s, t
    page 3 -- u, v, w, x, y, z, aa,bb,cc,dd
    page 4 -- ee,ff,gg,hh,ii,jj,kk,ll
    It would be nice if I could go to aa. 
    Jumping to the last post in the thread doesn't hack it. You have to spend a lot of time finding where you left off your reading.
    Intesting, the list of your posts on your homepage usings the term Last Activity were as Your Discussions uses the term Last Post. The terminalogy should be the same & should act the same.  For the existing capability of going the the last post, I was thinking of Goto Last Post.

  • Why does Messages not list message threads by date/time even when selected?

    Every thread in messages list messages out of date/time order even when selected.  How does one correct this or get them in the order I want?  Thanks!! BF

    HI,
    This happened with the Messages Beta as well as the full version in Mountain Lion.
    In both cases if one device was Off line whilst a conversation was going on the sync process when the device was turned on  would not be instant.
    It would fill in (sync) more like an only slightly speeded up chat.
    Consequently  if you were moving from a iPhone conversation to the Mac and turned the Mac On your Contacts new IMs could be mixed up with the Sync info arriving.
    At the same time even though the whole IM sending thing is time stamped there appears to be no way that the App or the iPhone or the Mac can recognise the timing and move them into the right order.
    There seem to be more reports of the Mac being Off and not updating the conversation properly than there are iPhones doing the same.
    That could be done to this area being about the Messages app compared to the iPhone Area.
    It could also be down to the way people hold their conversations in the first place.
    i.e.  we know about it but it is outside our ability to suggest something that fixes this.
    For the points
    7:23 PM      Friday; October 19, 2012
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"
      iMac 2.5Ghz 5i 2011 (Mountain Lion 10.8.2)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb (Snow Leopard 10.6.8)
     Mac OS X (10.6.8),
     Couple of iPhones and an iPad
    "Limit the Logs to the Bits above Binary Images."  No, Seriously

  • Retrieve list of threads.

    If an application has multiple threads running started by multiple classes, is there a simple way to get a list of all running threads, so we can safely shut them down?
    (ie the http listener receives the shut down message, but it doesn't know what other threads have been started by the other threads in the application, so simply exiting the webserver thread doesn't terminate the application)

    ThreadGroup will give you a list of active threads, but "safely shutting down" is another issue, because it's up to the thread's code to specify a way of safely shutting it down, so if you didn't write it there's no assured way.

  • Is C++ list is thread safe??

    we have a list<type name> which is accessed by two threads(update in one thread and deleted in another thread.)
    mutex_lock and unlock are used. is insert by one thread is not reflected in another thread.
    any reason?

    When building a multi-threaded program, all CC command lines must include the -mt option. In that case, the default libCstd and optional STLport C++ runtime libraries are thread-safe.
    Thread-safe means that the internal library code executed by different threads will not conflict. You still must provide your own guards for shared objects.
    For example, suppose you have two lists, L1 and L2. If L1 is accessed only by thread 1 and L2 is accessed only by thread 2, you do not need special locking. If L1 is accessed by more than one thread, you must synchronize access to L1 yourself. You do not need to worry about the individual list functions or the implementation details of the list in either case..

  • Problem with ioinning multiple Threads

    Hi,
    I have multiple sub Threads T1, T2, T3.... started by main Thread T. After starting each sub Thread, I stored them in the HashMap. When finish starting all Threads, I want to join each sub Thread to my main Thread.
    The problem is when T3 join with T, it hanged forever! Here is my code:
    class MyThread extends Thread
    private name;
    MyThread(String tName)
    name = tName;
    public void run()
    // doing something....
    public HashMap startThreads()
    HashMap tList = new HashMap();
    for (int i=0; i<5; ++i)
    String tName = "Thread" + i;
    MyThread myT = new MyThread(tName);
    myT.start();
    tList.put(tName, myT);
    public void joinThreads(HashMap tList)
    Iterator iter = tList.values().iterator();
    while (iter.hasNext())
    Thread activeThread = (Thread)iter.next();
    if (activeThread.isAlive()) {
    System.out.println("Join alive thread " + activeThread.tName);
    activeThread.join();
    In my method:
    ... doing s/t
    HashMap tMap = startThreads();
    joinThreads(tMap);
    ... doing s/t else (never excecuted!!!)
    My purpose is staring multi Threads at the same time and executing some code after they all die.
    If I join my sub Thread right after creating it, then the other sub Thread couldn't started until subThread 1 dies!
    If I don't join the sub Thread but remove it from the thread Map when it's not alive then my code executed perfectly. I want to apply join method with my mutiple Threads, how ????
    Could some one give me a hint? Thanks.

    Hi,
    What I don't understand here is why the main Thread
    does not join all the sub Threads ?If you're getting a ConcurrentModificationException while iterating the list of threads, then that's why.
    Why main Thread
    has to wait for sub Thread 1 to finish before joinning
    next sub Threads?It has to join all of the threads. That means it has to wait for all of them to finish. In order to wait for all of the threads it has to wait for the first thread.
    I'm 100% sure that my sub Threads in
    the threadList are valid and alive since I already
    veriffied with other methods.I don't see what that has to do with your problem.
    I already set my joinThreads method as synchronized,
    how come I still have ConcurrentModificationException?Because the list was modified concurrently.
    How can I fix this error?Stop modifying the list concurrently. You haven't posted all of the relevant code, so I can't offer any clues about how to do that.

  • Thread Process is exiting without completing the process in SharePoint 2010 webpart

    We have implemented simple thread to process to excel upload into SharePoint 2010 custom list.
    Thread process running in local SharePoint 2010 environment (OS -Windows 7). Once we deployed in SharePoint server,
    Thread process is exiting without completing its proces.
    Please let us know if you know any resolution.
    Code is as below
    Thread thread = new Thread(new ThreadStart(UploadData)); //Upload is the method where data will insert into List
    Thread.Start();
    Marulasiddappa SB (Swamy)

    Hi,
    According to your post, an error occurred when you used Thread in SharePoint 2010 web part.
    Please can do as follows:
    1. Execute the  UploadData method to see whether it can work.
    2. Debug your solution in Visual Studio to get more information the error,
    It will be easier for us to research if you can provide more code.
    Best Regards
    Dennis Guo
    TechNet Community Support

  • A collection of threads: FAQ's, intros and memorable discussions

    Welcome to the SDN Security Forum!
    In addition to the information accessible via the SDN Security Main Wiki and the SDN Security Forum Search and
    searching the SAP Service Marketplace (see the thread on OSS Note Search Techniques), this "sticky post" lists some threads from the forum as:
    - an introduction for new members / visitors on topics discussed in threads,
    - a collection of some threads which provided usefull answers to questions which are frequently asked,
    - a collection of some memorable threads if you feel like reading some security related material.
    - a collection of OSS notes which have been proven to be generally usefull to know about.
    The listed threads will be enhanced from time to time. Please feel welcome to contact me via the details in my SDN Business Card if you would like to suggest any threads for inclusion here.
    Keeping an eye on the SDN Security Homepage for relevant blogs (often there are security aspects to other blogs as well),
    the Security Area of the SAP Service Marketplace ("OSS" logon required) and subscription to the SAP Security Newsletter
    can also be generally recommended if you are interested in security.
    New!Also see SAP's Security Disclosure Guidelines and do not use SDN to report software bugs. Contact details are in the link.
    PS: When asking a question in the forum, please also provide sufficient information such that the question can be
    answered usefully, and when the question is answered please indicate which solution was found and close the thread.

    Identity Management
    CUA will never die! => Blog from SAP about CUA support myths.
    CUA information and advice needed!!! => There is a seperate dedicated forum for this now.
    User Management and Password Rules
    User Comparison => PFUD and "valid to" role assignments, and other search terms.
    Effect of Keeping User IDs => Why and how to avoid deleting user ID's.
    FORCE PASSWORD CHANGE => Think twice about updating SAP tables.
    ALEREMOTE ID locked by KRNL => Where did a (CaSe-sensitive) password come from and why did it fail?
    DDIC and changing ownership of Jobs => Restricting DDIC access and logging, by restricting it's use.
    Copy User Masters from 4.7 to ECC 6.0 => Old hats, new (easy) tricks and win a round of beers, instead of points
    Profile Parameter: login/password_logon_usergroup => Exceptions, development requests and analzing logon problems.
    Authorizations
    Trace => Contributing to SDN can enable a difference for everyone, depending on the reason code ...
    Security Design => Derived roles, role design and (potential) design errors.
    F110 - S_BTCH_ADM => S_BTCH_ADM vs. S_BTCH_JOB.
    How to securize SE16N => Be carefull with S_DEVELOP authorizations, regardless of S_TCODE.
    Giving authorization for img => Tcodes, activities and projects within SPRO.
    Role and Naming concpets => Important first step with lasting consequences.
    display access for the tcode SCC4 => Tweaking table auth groups with transaction SE54.
    No control over workbench tcode start => The "System => Status and F1 trick"; also see SAP note 1085326.
    Is SU24 only for removing security checks? => What the SU24 indicators are for.
    Effect of "changed' objects during upgrades => The rules of SAP note 113290.
    How to remove SPRO from SAP_ALL profile => The Neverending Story.
    How to create new org.level and further actions? => Reports for converting organizational level fields.
    Granting Authorization Group SC in S_TABU_DIS => New authorization object S_TABU_NAM to access individual tables.
    error while uploading roles from quality to production => Upload roles, or transport them.
    SUIM RSUSR010 does not return completed list of t-code. => Special SUIM reports explained by SAP guru Bernhard Hochreiter.
    Maintaining different values for Accounting Type (KOART) => A little bit of everything in PFCG which you need to know.
    Adding Object Mannully Vs. Adding Object in SU24 for Tranaction => When to use SU24 to make changes.
    Too many duplicate objects coming while adding Tcode through MENU => SU24, PFCG merge option and role design.
    Not add authorization objects that exist in role when adding transaction => Initial installation tuning of SU24.
    Do you give SAP_ALL and SAP_NEW to developer in Dev and QA environtment? => Developer type authorizations.
    Errors occurred during post-handling PRGN_AFTER_IMP_ACTGROUP_ACGR for ACGR => Solutions for profile name collisions.

  • Mods, could we get a sticky thread in the Logic Pro board?

    By my count there are upwards of thirteen separate threads asking if there is a free upgrade to Logic Pro X for recent buyers.  Could we get a sticky thread about it or FAQ (and maybe even lock the redundant threads)?  It's a bit maddening and I'm sure there will be many more.

    Look under the individual forums (column on the left), and there is a TAB for each of "User Tips".
    The list of threads continue to roll down as new threads are updated/created.  Any thread that stays in view forever would clog the arteries.

  • ThreadInfo's getThreadId() == java.lang.Thread's getId() ?

    Hi Folks
    I am trying to add MBean to show CPU consumption of various threads in my application.
    The threads created during the course of the application execution are maintained in a vector list.
    In my instrumentation code, I use this list of threads and
    a) iterate over each Thread instance and get its thread id ( thread.getId() )
    b) Using this long value, I determine the CPU consumption of this thread as :
    ThreadMXBeanInstance. getThreadCpuTime(threadId)
    However this does not seem to be giving me the correct value.
    On debugging using a generic program, where I print the thread ID , name, CPU consumption of all the threads in the JVM, as :
    ThreadMXBeanInstance.getAllThreadIds()
    for( each ThreadInfo...)
    //print attributes using ThreadInfo.getThreadName(..)..getThreadId(..)...etc..
    the thread ID printed by ThreadInfo.getThreadId() seems to be always +1 + the threadID got as in (a))+.
    Please let me know if you can throw some light on the above subject?
    ps : I am using Java 6, u10 on a WINXP, SP2 + 2CPU Intel Core processor with 2 GHz & 2GB memory.
    Great Thanks in advance.

    Hi,
    Are you sure you haven't made a mistake somewhere?
    Here is a small program that iterates over the threads and print their name and thread id has obtained from Thread and ThreadInfo. I've run it on JDK 6u10 and as you can see the information match. What do you get if you run it on your install? (hint: run it with -Dcom.sun.management.jmxremote to get the same results than I).
    Here the program:
    package threadid;
    import java.lang.management.ManagementFactory;
    import java.lang.management.ThreadInfo;
    import java.lang.management.ThreadMXBean;
    * @author dfuchs
    public class Main {
         * @param args the command line arguments
        public static void main(String[] args) {
            // TODO code application logic here
            final ThreadMXBean tmb = ManagementFactory.getThreadMXBean();
            final Thread[] ts = new Thread[tmb.getThreadCount()];
            ThreadGroup tg = Thread.currentThread().getThreadGroup();
            while (tg.getParent()!=null) {
                tg = tg.getParent();
            tg.enumerate(ts,true);
            for (Thread t : ts) {
                if (t==null) continue;
                final ThreadInfo ti = tmb.getThreadInfo(t.getId());
                System.out.println(t.getName()+"[id="+t.getId()+"]: name=" +
                        ti.getThreadName()+", id="+ti.getThreadId());
    }Here is the output:
    Reference Handler[id=2]: name=Reference Handler, id=2
    Finalizer[id=3]: name=Finalizer, id=3
    Signal Dispatcher[id=4]: name=Signal Dispatcher, id=4
    RMI TCP Accept-0[id=9]: name=RMI TCP Accept-0, id=9
    main[id=1]: name=main, id=1Hope this helps,
    -- daniel
    [http://blogs.sun.com/jmxetc|http://blogs.sun.com/jmxetc]

  • Can I ensure a single thread of execution on an activity ?

    Hi,
    11.1.1.7 BPM
    To go with my list of threading/correlating/synchronizing questions how can I ensure that an activity will start and complete without another thread/instance running the same activity at the same time ?
    cheers
    Tony

    Not exactly.
    You will find yourself nudging the page up or down a bit. Earlier versions of iOS Pages allowed "full page view" but that really wasn't full page either. You can squeeze the view to fit, but as soon as you release it, the document springs back to normal size - it is only about a line off from what you are looking for.
    An alternative would be to view a Pages Document as a PDF and view the PDF in an app such as GoodReader - there you can see both the top and bottom edges of each page. There are many other PDF viewers available in the App Store.
    Hope this helps.

  • Selecting next thread broken after deleting previous thread since yesterday

    I read large mailboxes for mailing lists with threading enabled, and generally have the threads collapsed.
    Starting yesterday, when I delete a thread (or single message), it now starts to select the next thread, but then unselects everything after something like 3/4 of a second.
    That's if the thread is collapsed. If its not collapsed, it now selects ALL the messages in the thread instead of the initial summary pseudo-message giving the index of the messages in the thread. Apparently, if the thread is collapsed, it can't do that, and it gives up.
    It used to select the index of the thread. This selecting all the messages (and not the index) is not useful in any way I can imagine.
    How do I get the old behavior back?
    Thanks!

    I just saw the "Sort by Date" drop-down menu - it allowed me to sort by ascending date, so now I can do what I want.  Sorry about the ignorant post.
    tom

  • Search and find 'open' threads: request of advanced search features

    Hello,
    time is passing by quickly... Hence it happens that some threads I have started with a question / problem are still open, waiting for some further investigation etc.
    However, after a few days the post has disappeared from the first forum page - and soon thereafter from my memory. All I remember is that there were a few open threads
    So here is my question / suggestion for the forum: A feature to list all threads I have started but not marked as solved would be quite handy in such cases... Phrased differently, I'd like to have an advanced search capability where one can not only search for a given word, but also for certain metadata such as author, solved/unsolved, etc.
    Thanks and have a nice day,
    Wolfgang
    Solved!
    Go to Solution.

    Wolfgang wrote:
    Thanks, tst, but as you concur there is no chance to find the open, unsolved threads - only solved ones... I don't mind to first use regular search, but even the advanced options don't resolve my request...
    Yes there is.
    Attachments:
    unsolved.PNG ‏5 KB

  • DatabaseConnections has no JNDI context so cannot list connections

    All my connections are missing and I cannot create or save new ones.
    The messagse from the logging page are:
    oracle.jdevimpl.db.adapter.DefaultContextWrapper -
    failed to create naming Context for db connections at url: file:/C:/Documents and Settings/PhilDeFrancesco/Application Data/SQL Developer/system1.5.1.54.40/o.jdeveloper.db.connection.11.1.1.0.22.49.42/connections.xml
    oracle.jdeveloper.db.DatabaseConnection
    DatabaseConnections has no JNDI context so cannot list connections

    The thread suggesting changes to .jar files did not work:
    http://forums.oracle.com/forums/ann.jspa?annID=737
    However,
    I found this on another thread and it worked for me.
    Connection problems with SQL Developer -- ANSWERED
    "Try removing the SQL Developer SYSTEM folder that is created on Startup.
    \Documents and Settings\<user>\Application Data\SQL Developer\system1.5.0.53.38.
    Note that this will remove any connections and settings created, but as you are not able to import or create connections, that should not be a concern. This system folder is created when you first invoke SQL Developer and is updated while you work, storing and preserving connections and various settings as you work. "

  • Some question on thread

    i think threads are unpredictable.say, the following code. some questions on the code.
    public class Rpcraven{
         public static void main(String argv[]){
         Pmcraven pm1 = new Pmcraven("One");
         pm1.run(); // line1
         Pmcraven pm2 = new Pmcraven("Two");
         pm2.run();  // line 2
    class Pmcraven extends Thread{
    private String sTname="";
    Pmcraven(String s){
         sTname = s;
    public void run(){
         for(int i =0; i < 2 ; i++){
              try{
               sleep(1000);
              }catch(InterruptedException e){}
              yield();
              System.out.println(sTname);
    }question 1 > note line 1 and line 2 . does this two threds are staarted at the same time ? or line 1 first and line 2 second as in the code ? this is very much important to me.
    question 2 > ok, whoever goes first , now lets come to the try-catch block . there is sleep() who will sleep first ? so i need to know which thread is going to sleep first ? bcoz then i can say who will get the yield() method.
    i find difficult to predict the output of this thred.
    Output of One One Two Two.
    one more thing, threads are always called by start() method ( run() is called implicitly) . here start() is not usued . still the code is working . how ?

    question 1 > note line 1 and line 2 . does this two
    threds are staarted at the same time ? or line 1 first
    and line 2 second as in the code ? this is very much
    important to me.If it's important, you are doing something wrong...
    First, you shouldn't call the threads' run() method, that doesn't "start" the thread, it just calls run(). Use start() instead.
    The threads are sort of started in order, but probably not in the way you think.
    Think of it like this: there is a list of threads in the JVM. start() puts the thread in the list. After that, the CPU of your computer can run any thread in the list, for as long as it feels like. The CPU might run thread 1 for a few instructions, then thread 2 for a while, or it might start with thread 2, ... If you have a multi-CPU machine, the threads are run at the same time. It's unpredictable, except when you do explicit synhcronization or waiting.
    question 2 > ok, whoever goes first , now lets come to
    the try-catch block . there is sleep() who will sleep
    first ? so i need to know which thread is going to
    sleep first ?This is unpredictable. You can't know it. It will vary from run to run.
    If you need two threads to do something in a predictable order, you'll need to do synchronization and waiting.
    one more thing, threads are always called by start()
    method ( run() is called implicitly) . here start()
    is not usued . still the code is working . how ?You are not starting the threads, you are calling their run() methods sequentially.

Maybe you are looking for

  • Here's how to do ALV (OO) with dynamic fcat, int table and editable data

    Hi everybody Here's a more useful approach to ALV grid with OO using dynamic table, data NOT from DDIC, dynamic FCAT and how to get changed lines from the grid when ENTER key is pressed. It's really not too dificult but I think this is more useful th

  • ASSIGNING REPORTS AND URL LINKS IN ROLE

    Hello Gurus, could you please tell me the procedure of asigning Reports, specific tables and Url links in the role.actually i know the process of assigning T-Codes to the role but i dont know the procedure for reports and url links and tables... i ho

  • How the storage will be allocated on Undo tablespace made of datafiles?

    I have a UNDO tablespace with two data files. Wherein one data file with Auto Extend as Yes and other as No. In the case of multiple datafiles in UNDO tablespace, 1. Will the storage be allocated of same size on each datafile ? 2. What will be the ca

  • SIP Client for Symbian (Nokia N91)

    Anybody have a SIP Client for Nokia N91 (Symbian OS)or knows dates of releases, links, any thing? Thanks Juan

  • IT 2002 & IT 2003

    Hi All, I am in serious need of help, I am currently working on performance tuning a piece of legacy code, the thing is I have done everything that I can: but the report still runs for like 12hours and counting, it was 14hours. The client is currentl