Software causes
The beach ball can also be caused by software. An application can hang in an infinite loop or simply be inefficient. A background process can run amok. An errant third-party plug-in can turn an app into a slug. If you suspect that software is the problem, wait a few minutes to see if the application responds or crashes. While you’re waiting, open Activity Monitor (if you can) and check the % CPU column to see which apps are hogging CPU cycles. 

If the application doesn’t resume, it should appear in Activity Monitor in red text, with the words Not Responding next to its name. If it’s an application you opened, select it, click on Quit Process, then on either Quit or Force Quit.

If you can switch to other applications and the Spinning Beach Ball of Death appears in all of them, that could mean a system process is hung up. In that case, you should try to shut down or restart your Mac by pressing C-Eject or C-Control- Eject, respectively. 

Trying to use a sleeping disk can summon the beach ball. Turn off sleep in the Energy Saver preference pane

Otherwise, press and hold the power button to shut down your Mac and restart. When the system is back up, check Console (/Applications/Utilities) to see if you can determine the cause.

You can’t prevent every instance of the Spinning Beach Ball of Death – after all, it is there to inform you that your Mac is busy – but a little patience and the occasional forced quit or restart should help make those instances just that bit more bearable.