-1
/** traversing elements */
import java.util.*;
class Traversor extends Thread
{
Enumeration e;
public Traversor(Enumeration e)
{
this.e=e;
}
public void run()
{
System.out.println("new thread started, traversing vector elements.....");
while(e.hasMoreElements())
{
System.out.println(e.nextElement());
try
{
Thread.sleep(4000);
}
catch(Exception ex)
{}
}
System.out.println("new thread completed");
}
}
class vectortest{
public static void main(String args[])
{
System.out.println("main thread started, creating vector...");
Vector v=new Vector();
v.addElement("one");
v.add("three");
v.add(1,"two");
Enumeration e=v.elements();
System.out.println("vector created ,enumeration obtained");
Traversor th=new Traversor(e);
th.start();
System.out.println(" new thread launched , suspending main thread");
try{
Thread.sleep(1000);
}
catch(Exception ex)
{}
System.out.println("main thread resumed,modifying vector");
v.add("four");
v.add("five");
System.out.println("vector modified, main thread completed");
}
}
Пожалуйста, будьте более конкретным по вашему вопросу. Кроме того, вы, кажется, использует устаревшие классы '' VECTOR' и Enumeration' вместо '' ArrayList' и Iterator', вы последовавший очень старый учебник/книгу? – Kayaman
Вопросы просят отладки помощи должны содержать [ясный, проверяемый и минимальный] (http://stackoverflow.com/help/mcve) пример, и включают в себя желаемое поведение. Это ничего не дает! – Docteur
Кроме того, этот код полностью не читается. Отступьте это правильно. –