For me, I'll at least start by bashing on it until I think I've solved it. If I get totally stuck, like "I just don't see anything useful to do in this position at all..."), I will put it down and come back to it later - sometimes after a few hours, sometimes the next day or a couple days later. Sometimes in that situation, even if I spend 20 or 30 minutes searching for a solution but not finding anything, I will occasionally see it right away the next time I look at it. If I go through a couple of cycles of this and still can't find a solution, I will assume I'm just not going to find it in any finite amount of time, and will abandon the search and look at the solution. This is actually very instructive for me most of the time, it usually shows me something I just wasn't considering at all, and next time I see a position like that I remember because of all the time I spent staring at the problem that I couldn't solve.
The more common problem for me is when I look at a problem and think I solved it, then I look at it more to make sure I solved it and can't find a better move, and then I look at the solution - and I'm wrong... Often because I missed something totally obvious, like I've hung a piece, or missed a mate threat, or didn't notice from the position that I was actually in check to start with... Unfortunately, with problems in a book, in that situation all you can do is read the solution, try to understand why your proposed solution was wrong, and learn from that. If you're working on a problem using some kind of software, at least it will usually tell you, no that's not the answer, try again - without revealing what the answer actually is.
In the end, I guess it really does depend on how you learn best, and to some extent how much time you can devote to study. In my case, my study time is limited, and I just can't afford to get stuck indefinitely on one problem, I need to be able to use the time I have to look at as many problems as I can, and learn what I can from them.