Multithreading ਇੱਕ Java ਪ੍ਰੋਗ੍ਰਾਮ ਨੂੰ ਇੱਕੋ ਸਮੇਂ ਮਲਟੀਪਲ threads ਚਲਾਉਣ ਦੇਣ ਦਿੰਦਾ ਹੈ, ਜੋ parallelism (ਮਲਟੀਪਲ CPU cores ਦਾ ਉਪਯੋਗ) ਅਤੇ responsiveness (ਬਲੌਕ ਕੀਤੇ ਬਿਨਾਂ ਕੰਮ ਕਰਨਾ) ਨੂੰ ਸਮਰਥ ਬਣਾਉਂਦਾ ਹੈ। Java ਕੋਲ first-class thread support ਹੈ — ਪਰ shared mutable state ਗੁੰਝਲਦਾਰਤਾ (race conditions) ਲਿਆਉਂਦਾ ਹੈ ਜਿਸ ਨੂੰ ਸਾਵਧਾਨੀ ਨਾਲ ਪ੍ਰਬੰਧਿਤ ਕਰਨਾ ਚਾਹੀਦਾ ਹੈ।
Threads ਬਣਾਉਣਾ
() -> System.out.println( + Thread.currentThread().getName());
(task);
t.start();
Executors.newFixedThreadPool();
executor.submit(task);
