Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML
 
 
Search All Tutorials
  

 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Thread Access through the Hash Table in Java

                         

Here, you will learn about how a thread is accessed by using the hash table in Java. 

 

 

Here is the code of the program:

 

 

 

 

import java.util.*;

public class ThreadedAccess implements Runnable{
  static int ThreadCount = 0;
  public void run(){
    String s = "This is thread " + ThreadCount++;
    Vector<String> v = new Vector<String>();
    v.addElement(s);
    v.addElement(s);
    try{
      Thread.sleep(2000);
    }
    catch(Exception e){}
    v.addElement(s);
    System.out.println(v);
  }
  
  public static void main(String[] args){
    try{
      for(int i = 0; i < 5; i++){
        (new Thread(new ThreadedAccess())).start();
        try{
          Thread.sleep(200);
        }
        catch(Exception e){}
      }
    }
    catch(Exception e){
      e.printStackTrace();
    }
  }
  private static ThreadLocal<Vector> vectors = new ThreadLocal<Vector>();
  public static Vector getVector(){
    Vector v = (Vectorvectors.get();
    if (v == null){
      v = new Vector();
      vectors.set(v);
    }
    return v;
  }
  private static Hashtable<Thread,Vector> hvectors = new Hashtable<Thread,Vector>();
  public static Vector getVectorPriorToJDK12(){
    Vector v = (Vectorhvectors.get(Thread.currentThread());
    if(v == null){
      v = new Vector();
      hvectors.put(Thread.currentThread(), v);
    }
    return v;
  }
}

Download this example.

                         

Facing Programming Problem?
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

6 comments so far (post your own) View All Comments Latest 10 Comments:

Hi wanted to say hello to members of this great and helpful site pleased to
be part of your wonderful forum.

Posted by wookyha on Saturday, 08.2.08 @ 17:04pm | #70543

new to the forums

glad to be a member... just wanting to say hi

whats up everyone?

Posted by adhehousa on Wednesday, 07.30.08 @ 15:52pm | #69971

The www.roseindia.net is good site.
Respect, webmaster.

Posted by on Wednesday, 07.30.08 @ 03:29am | #69864

I am wondering if any of you have ever bought a replica rolex and do you find the quality is decent like a real rolex or not, I was considering to buy from this site <a href=http://www.swissprecise.com>Rolex Replica</a> but need some help...

Posted by Omivaseivelar on Monday, 07.7.08 @ 05:45am | #66053

Hi,

my name is Tina i am new here i found this website today
and i like it. I will first keep reading and i am sure i will
have a lot of questions. Sorry for my bad English i am
from Norway but i stay in Germany as exchange student
for a year.

Best Tina

Posted by Sexcam on Tuesday, 06.3.08 @ 15:10pm | #61946

Hello everyone!
I love you!

Posted by Frattywinty on Tuesday, 05.13.08 @ 10:31am | #59664

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Hot Web Programming Job

Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.