For me, trying to force focus never really works. My standard is to take a long walk if I find my mind wandering a lot.<p>Alternatively, if I can’t focus on a particular task, I’ll work on something else for a while.
I work in my office with the doors closed, no TV or music playing, and I choose what I'm going to work on and get started on it.<p>I work until I reach a goal or hit a wall and then take a short break by opening up some News or Facebook and read a bit to give my head a rest, and then either get back to where I was stuck or move on to the next step in what I'm working on.<p>I don't stress out over not being able to solve a problem on the first shot. If I need to look for an answer to a question or solution to a problem I don't sit there and try to figure it out on my own, I start poking around Stackoverflow or do some searching for what I need to know first.<p>I almost always find what I need, and in those rare cases I cannot I will ask a question wherever it's most appropriate and generally someone points me in the direction I need to go. In the meantime I'll choose something else I need to work on, generally something I know I can easily make some progress on.<p>I've found there is almost nothing I need to do that hasn't been done and documented somewhere and it's a waste of time to try and "resolve" things that already have a solid solution and I learn something every time I do that.<p>As long as I'm learning or making progress it's easy to stay focused and be productive. Those short breaks I take when I hit a wall give me a chance to come back to a problem and look at it with a fresh perspective. This way I never feel like it's impossible to overcome, or, worse yet, I'm not up to the challenge.
Are you talking about big picture focus (working on the right things)? Or little picture focus (getting into a flow state so you can finish the task at hand)?