java 2 3
fdsa
fdsa
Set of flashcards Details
Flashcards | 496 |
---|---|
Language | Deutsch |
Category | Computer Science |
Level | Other |
Created / Updated | 06.12.2020 / 24.01.2021 |
Weblink |
https://card2brain.ch/box/20201206_java_2_3
|
Embed |
<iframe src="https://card2brain.ch/box/20201206_java_2_3/embed" width="780" height="150" scrolling="no" frameborder="0"></iframe>
|
Whats the difference between calling Thread.run() and Thread.start()?
Thread.run will just execute the method and doesnt start a new thread
Whats the signature of Thread.sleep?
public static void sleep(long millis) throws InterruptedException
Do we have to shutdown an ExecutorService?
Yes, if not then the application will never terminate
What happens if a new Thread is submitted to a ExecutorService while it is shutting down?
RejectedExecutionException will be thrown
How to cancel a running/upcoming task in an executorService?
List<Runnable> shutdownNow()
What is returned by ExecutorService.shutdownNow?
A List<Runnable> of tasks that were submitted but never started
Can we use try-with-resources for ExecutorServices?
No, doesnt implement AutoClosable
How to execute a Runnable task at some point in the future? with a ExecutorService? (Signature)
void execute(Runnable command)
How to execute a Runnable task at some point in the future and return a Future representing the task with a ExecutorService? (Signature)
Future<?> submit(Runnable task)
How to execute a Callable tasks at some point in the future and return a Future representing the pending result of the task with a ExecutorService? (Signature)
<T> Future<T> submit(Callable<T> task)
How to execute the given tasks and wait for all tasks to complete and return a list of Future instances in the same order they were in the original collection with a ExecutorService? (Signature)
<T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException
How to execute the given tasks and wait for at least one to complete and return a future instance for a complete tasks and cancel any unfinished tasks with a ExecutorService? (Signature)
<T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException
Whats the Signature of the Future-method for returning true if the task was completed/threw exception/cancelled?
boolean isDone()
Whats the Signature of the Future-method for returning true if the task was cancelled before it completed normally?
boolean isCancelled()
Whats the Signature of the Future-method for attempting tio cancel execution fof the task and returning true if it was successfully cancelled of false if it could not be cancelled/is complete
boolean cancel(boolean mayIntteruptIfRunning)
Whats the Signature of the Future-method for retrieving the ruslt of a task, waiting endlessy if it is not yet availiable
V get()
Whats the Signature of the Future-method for retrieving the result of a task, waiting the specified amount of time. If the result is not ready by time throw a checked TimeoutException
V get(long timeout, TimeUnit unit)
Whats the returntype of Future.get when its the return of a Runnable?
will be allways null
Whats the definition of the Callable interface?
@FunctionalInterface public interface Callable<V> {
V call() throws Exception;
}
When are Runnable and Callable interchangable?
When the lambda does not throw an exception and there is no returntype
What does the ExecutorService.awaitTermination do?
waits the specified time to complete all tasks, returning sooner if all tasks finish or an InterruptedException is detected
What is the syntax of ExecutorService.awaitTermination?
boolean awaitTermination(long timeout, TimeUnit unit)
What happens if we call awaitTermination without calling shutdown before?
The thread will wait the full timeoutvalue sent with awaitTermination
Are invokeAll and invokeAny synchronous or aysnchronous?
synchronous -> wait until the result are avaiable before return control to the enclosing programm
Can we store a ScheduledExecutorService in a ExecutorService-variable?
Yes but doing so would mean we'd have to cast the object to call any scheduled methods
Whats the signature in a ScheduledExecutorService for creating and executing a Callable task after a given delay?
<V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit)
Whats the signature in a ScheduledExecutorService for creating and executing a runnable task after a given delay?
ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit)
Whats the signature in a ScheduledExecutorService for creating and executing a runnable task after a given initial delay, creating a new task every period value that passes?
ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit)
Whats the signature in a ScheduledExecutorService for creating and executing a runnable task after the given initial delay and subsequently with the givern delay between the termination of one execution and the commencement of the next?
ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit)
How to create an ExecutorService for single-threads with uses an unbounded queue and processes sequentially in the order in which they are submitted?
ExecutorService.newSingleThreadExecutor()
How to create an ExecutorService for a signle-threaded executor that can schedule commands to run after a given delay or execute periodically?
ScheduledExecutorService.newSingleThreadScheduledExecutor()
How to create an ExecutorService for creating a thread pool that creates new threads as needed but will reuse previously constructed threads when they are available?
ExecutorService.newCachedThreadPool()
How to create an ExecutorService for creating a thread pool that reuses a fixed number of threads operationg of a shared unbounded queue?
ExecutorService.newFixedThreadPool(int)
How to create an ExecutorService for creating a thread pool that can schedule commands to run after a given delay or to execute periodically?
ScheduledExecutorService.newScheduledThreadPool(int)
When is the usage of a newCachedThreadPool-Executor recommended?
For pools that require executing many short-lived asynchronous task.
What are the three main atomic-classes?
AtomicBoolean, AtomicInteger, AtomicLong
What does an monitor support?
mutal exclusion
Is this threadsafe?
for(int i=0; i<10; i++= {
synchronized(manager) {
service.submit(() -> manager.incrementAndReport());
}
}
No, we've synchronized the creation of the threads but not the execution ot the threads
What object is uses as a monitor for static synchronized methods?
The classObject, f.e. SheepManager.class
public static synchronized void printdayswork() in the class SheepManager would be the same as:
synchronized(SheepManager.class)
Which framework could we use when we want to check wheter a lock is avaiable and, if its not, perform some other task?
Lock-Framework