main thread
The first thread a program starts with; in a browser page it also runs JavaScript and handles input, layout and painting.
In more detail
Other threads are usually started from it, and a long-running task on it blocks everything else it handles: in a browser, clicks wait and animations freeze. Keeping main-thread work short, yielding often and moving heavy work to worker threads keeps programs responsive.
Examples
Java: the main thread runs the main method.In Node.js the main thread runs the event loop and every callback; heavy work belongs in worker threads or the libuv thread pool.React time slicing breaks rendering into pieces that let the main thread handle input in between.Related terms
- event loop — The central loop of an asynchronous program that waits for events, such as timers firing or data arriving, and runs the matching callbacks.
- long task — A task that keeps the main thread busy for more than 50 milliseconds, long enough for users to notice lag.
- Web Worker — A script that runs on its own background thread, separate from the page's main thread, so heavy computation does not freeze the page.
- compositor thread — A browser thread, separate from the main thread, that combines layers into frames and can scroll and run some animations on its own.
- thread — A path of execution inside a process that the operating system schedules on a processor; one process can have many.
- main method — The method the JVM calls first when it starts a program: public static void main(String[] args).
- Total Blocking Time — A lab metric adding up how long the main thread was blocked by long tasks while the page was loading.
- next/script — The Next.js Script component, which loads third-party JavaScript with a chosen strategy so it does not block the page.
- worker threads — The Node.js module for running JavaScript in parallel threads inside one process, each with its own V8 isolate and event loop.
- time slicing — Splitting a long job into short slices and giving control back to the browser between them so the page stays responsive.
- frame — One screen update; browsers aim for about 60 frames per second, which leaves roughly 16 milliseconds to do each frame work.
- microtask — A small job, such as a promise callback, that runs as soon as the current piece of JavaScript finishes, before the event loop handles anything else.
Taught in
- Critical Rendering Path: Preload, Prefetch And Scripts — Frontend Architecture & Web Platform
- Passive Listeners, Scroll Performance And Touch Interactions — Frontend Architecture & Web Platform
- The Browser Event Loop: Call Stack, Microtasks And Macrotasks — Frontend Architecture & Web Platform
- requestAnimationFrame vs requestIdleCallback: High-FPS Work — Frontend Architecture & Web Platform
- Web Workers: Off-Thread Computation And Structured Clone — Frontend Architecture & Web Platform
- Core Web Vitals: Measuring And Optimizing LCP, INP, And CLS — Frontend Architecture & Web Platform
- Concurrency Basics: Threads And Runnable — Modern Java: Virtual Threads & High-Throughput Services
- Script Optimization: next/script & Lazy Third Parties — Next.js 15 & Modern App Router Architecture
- libuv Architecture: Event Demultiplexer & Thread Pool — Node.js Internals & Backend Services
- Timers Phase: setTimeout, Min-Heap Scheduling & Drift — Node.js Internals & Backend Services
- Worker Threads: worker_threads & SharedArrayBuffer — Node.js Internals & Backend Services
- Virtual DOM vs Real DOM: The Reconciliation Cost Model — React 19 & Modern Component Architecture
- Concurrent Mode: Interruptible Work And Lane Priority — React 19 & Modern Component Architecture