Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2010
    Posts
    1
    Rep Power
    0

    Default Adding elements in array list and vectors using threads

    hi!
    can any one tell me how to add 100 of elements in array list and vector using threads...actually i want to prove that array is not type safe and vector is type safe..i want to do this using 100 of threads..
    the code i tried is given below

    package javaapplication4;

    import java.util.*;
    class XThread extends Thread {
    ArrayList<Integer> list = new ArrayList<Integer>();


    public XThread( int i){


    System.out.println("thraed"+i);
    }

    public void run() {

    list.add(5);

    System.out.println(list.size());
    }
    }
    public class Main {



    public static void main(String argv[]) {
    ArrayList<Integer> list = new ArrayList<Integer>();


    Thread thread[] = new XThread[25];

    //Start the threads
    for(int i=0;i<25;i++){
    thread[i]=new XThread(i);
    thread[i].start();


    }

    }}
    this code always print a size of 1...

    plz help me...
    Regards
    Honee

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,575
    Rep Power
    23

    Default

    prove that array is not type safe and vector is type safe
    Not sure what you mean by "type safe"?
    Your posted code doesn't have either an array or a vector.

    What is the posted code supposed to do?
    Why do you expect it to print out something different than what it does?

  3. #3
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Why would size ever be greater than 1? you make a new reference everytime in static main(), no idea what you are trying to achieve when you say you are proving array is not type safe, arrays wont compile without a type, do you mean arraylists?? still confused, since proper implementation of them require a type unless you are trying to break what java has provided for.

Similar Threads

  1. cant read xml elements into list
    By webdriver in forum New To Java
    Replies: 4
    Last Post: 08-09-2010, 08:43 PM
  2. adding list to an array element
    By Preethi in forum New To Java
    Replies: 5
    Last Post: 09-25-2008, 04:23 AM
  3. Adding elements to an Object Array
    By aneesahamedaa in forum New To Java
    Replies: 4
    Last Post: 09-07-2008, 03:55 PM
  4. going from vectors to linked list?
    By cbrown08 in forum New To Java
    Replies: 3
    Last Post: 12-01-2007, 12:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •