JAI4J (Job Assignment Infrastructure for Java) is a thin layer of {@linkplain it.unimi.dsi.jai4j.Job job} assignment upon which large systems of identical cooperating agents can be built. The original motivation of JAI4J is web crawling, where a job is a page (defined by a URL), and many identical agents fetch pages. After fetching, each agent parses its pages and generates new jobs as it finds new hypertext links.

The central concept of JAI4J is that of a {@link it.unimi.dsi.jai4j.JobManager}, a class that encapsulates all the logic related to communication and distribution of jobs. Ideally, each agent has a corresponding job manager (either by inheritance or by delegation) that is responsible for encoding and decoding messages (by converting jobs to and from list of bytes) and for keeping track of all currently alive job managers (and thus agents). The implementation {@link it.unimi.dsi.jai4j.jgroups.JGroupsJobManager} uses JGroups to this purpose.

A set of connected job managers is viewed by JAI4J as a single distributed queue for processing jobs. Jobs can be submitted to the queue using {@link it.unimi.dsi.jai4j.JobManager#submit(it.unimi.dsi.jai4j.Job)} (invoked on any job manager that is part of the set). The job will be {@linkplain it.unimi.dsi.jai4j.JobManager#receive() received} at some point in the future by some job manager in the set (possibly the same). In general, implementations of {@link it.unimi.dsi.jai4j.JobManager} use an {@link it.unimi.dsi.jai4j.AssignmentStrategy} to choose the receiver, but this is not necessary. The only constraint is that the job manager responsible for a job depends only on the set of currently known (and possibly alive) job managers.

Job managers usually take as arguments strategies and factories that customize their behavior. For instance, a {@link it.unimi.dsi.jai4j.dropping.DroppingThreadFactory} generates threads that drop job managers suspected of being dead. There are factories that generate threads dropping job managers immediately, and factories waiting some time. In the same vein, a {@link it.unimi.dsi.jai4j.dropping.PendingMessagesStrategy} decides what to do with messages that should have been sent to a dropped job manager: whether to {@linkplain it.unimi.dsi.jai4j.dropping.DiscardMessagesStrategy discard} them, for instance, or {@linkplain it.unimi.dsi.jai4j.jgroups.RedistributeMessagesStrategy redistribute} them.

An essential input to a job manager is usually an {@link it.unimi.dsi.jai4j.AssignmentStrategy}—an object specifying which job manager is responsible for a given job. Such strategies extend the {@link java.util.Set} interface, and set operations are interpreted as addition or dropping of a job manager. The {@link it.unimi.dsi.jai4j.AssignmentStrategy#manager(it.unimi.dsi.jai4j.Job) assign()} methods then decide which job manager is responsible for a job. A classical strategy is that based on {@linkplain it.unimi.dsi.jai4j.ConsistentHashAssignmentStrategy consistent hashing}.