Phase locking of Josephson junctions in two-dimensional arrays