Which preposition is correct and what is the difference in meaning if any?
I went to the gym, something I haven't done for a long time.
I went to the gym, something I haven't done in a long time.
Barrie's answer is correct for the case you used as an example. However, when referring to the future, only "for" is correct.
Both are grammatical. There's no difference in meaning, but, at least in the UK, in a long time could be a class marker.
We have been living here for a long time. (present perfect continuous) - It began in the past, and still lasts.
They lived in New York for a long time. (past simple) - The action began and finished in the past.
They will do it in a long time. (future simple) - It will begin and be finished a long time from now, in the future.
for a long time (present perfect (continuous)) - past - present - future
for a long time (past simple) - past
in a long time - future