Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/test", "user", "password");
ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
MyBean myBean = context.getBean(MyBean.class);
Java PCB(Process Control Block) 컨텍스트 스위칭
class PCB {
int pid; // Process ID
String state; // Process state
int programCounter; // Program counter
int[] registers; // CPU registers
int priority; // Process priority
public PCB(int pid, String state, int programCounter, int numRegisters, int priority) {
this.pid = pid;
this.state = state;
this.programCounter = programCounter;
this.registers = new int[numRegisters];
this.priority = priority;
}
public void saveState(int programCounter, int[] registers) {
this.programCounter = programCounter;
System.arraycopy(registers, 0, this.registers, 0, registers.length);
}
public void loadState() {
// Load the saved state (this is a simplified example)
System.out.println("Restoring state for process " + pid);
}
}
public class ContextSwitching {
public static void contextSwitch(PCB current, PCB next) {
// Save the state of the current process
int currentProgramCounter = 100; // Example value
int[] currentRegisters = {1, 2, 3}; // Example values
current.saveState(currentProgramCounter, currentRegisters);
// Load the state of the next process
next.loadState();
// Update the process states
current.state = "READY";
next.state = "RUNNING";
}
public static void main(String[] args) {
PCB process1 = new PCB(1, "RUNNING", 0, 3, 1);
PCB process2 = new PCB(2, "READY", 0, 3, 1);
contextSwitch(process1, process2);
}
}