Is there any way to create kind of transactions using only Java SE? For example, we have some class with main and an input method. What we do is putting in console some numbers, adding'em to a list and then return this list. But, if user doesn't put any number in console for a 5 sec - program clears out our list, returns this empty list and stops.
And dummy code for example:
public class SomeClass {
public static void main(String[] args) {
inputNumbers().forEach(System.out::println);
}
public List<String> inputNumbers() {
Scanner scanner = new Scanner(System.in);
List<String> result = new ArrayList<>();
for (int i = 0; i < 10; i++) {
result.add(scanner.nextLine());
//if nothing happen within 5 sec
//result.clear();
//return out empty result;
}
return result;
}
}