Please explain how to implement a multi-threaded application!
There is a class of type CRUD with static methods and a collection with elements:
public class Crud { protected static List<User> users = Collections.synchronizedList(new ArrayList<>()); static { initialize(); } protected static void initialize() { users.add(new User("Name1", "Surname1", 27)); users.add(new User("Name2", "Surname2", 27)); users.add(new User("Name3", "Surname3", 26)); users.add(new User("Name4", "Surname4", 26)); users.add(new User("Name5", "Surname5", 28)); } public static void insert(User user) { users.add(user); } public static void delete(int index) { users.remove(index); } public static void update(int index, User user) { users.set(index, user); } public static void show() { Iterator it = users.iterator(); while (it.hasNext()) { User user = (User)it.next(); System.out.println(user.toString()); } } public static void show(int index) { User user = users.get(index); System.out.println(user.toString()); } } You need to implement multi-threading in the main(String[] args) method to simultaneously extract and modify data in the collection.
This is a purely test application, not an implementation, purely for educational purposes.
Thank you in advance for your help.
next()calls, another thread can easily intervene by adding or deleting an element). Therefore, it will be possible to refuse the wrapper and synchronize any access to the collection (except for the designer) by hand. - andreycha