two possibilities that come to mind
You never said what computer you have, but there are two possibilities that come to mind:
Your battery is defective, your power supply jack has a broken solder connection, your CPU heatsink is clogged with dirt, or the operating system has been corrupted.
... I counted 4, but I agree.