If the thread has worn away, it can be built back up and re-machined but not while still attached to the bike. The shaft must be removed and metal sprayed back to oversize, then machined back to standard. Likely to cost more than a replacement shaft, and the heat applied as part of the process may affect the properties of the shaft. May also affect insurance in the event of an accident investigation involving any failure of the drive components. There are other, imaginative, ways to repair, including welding the sprocket on.