Thread.sleep() causes the current thread to pause for a time. If you call this from the main thread, the robot will be unresponsive for those 500 ms while the thread sleeps. You could avoid this by moving the solenoid code to a separate thread.
A simpler option that I often use is to record a timestamp at the start and then subtract that timestamp from future readings to get the elapsed time.
Example:
Code:
double startTime;
if (j_shooting.getRawButton(2)) {
// This will repeatedly be set until you let go of the button
startTime = System.currentTimeMillis();
} else if (j_shooting.getRawButton(1))
// This will override, but not reset, the timer
cyl_shoot.set(DoubleSolenoid.Value.kForward);
} else {
// Check the time to see if the pistons should be...
if (System.currentTimeMillis() - startTime < 0.5) {
cyl_shoot.set(DoubleSolenoid.Value.kReverse); // ...extended, or...
} else {
cyl_shoot.set(DoubleSolenoid.Value.kForward); // ..retracted
}
}
This way you aren't locking up the rest of your program while you wait for the pistons to retract.