Variational inequalities in Hilbert spaces with measures and optimal stopping problems