You typically use
taskset to restrict a process after it's been started. You could make use of the
pidof java to determine what the PID is for your Java application and then pass that to
$ taskset -p $(pidof java) --cpu-list 0-2,5
NOTE: If you had 6 CPUs, 0,1,2,5 would assign an affinity to these CPUs for your JVM's PID.
Keep in mind that affinity does not restrict other processes from using these CPUs,
excerpt taskset man page
taskset if more a tool of restricting a specific process or processes to a specific set of CPUs, not in restricting exclusivity.
taskset is used to set or retrieve the CPU affinity of a running process given its PID or to launch a new COMMAND with a given CPU affinity. CPU affinity is a scheduler property that "bonds" a process
to a given set of CPUs on the system. The Linux scheduler will honor the given CPU affinity and the process will not run on any other CPUs. Note that the Linux scheduler also supports natural CPU
affinity: the scheduler attempts to keep processes on the same CPU as long as practical for performance reasons. Therefore, forcing a specific CPU affinity is useful only in certain applications.
This self answered U&L Q&A titled: How to use cgroups to limit all processes except whitelist to a single CPU? covers the topic of how to accomplish this using cgroups.