Section 18. The compensation of all officers, assistants and employees of jails and houses of correction shall be paid by their respective counties, and shall be in full compensation for all their services. They shall devote their entire time, not exceeding the time limited by section forty of chapter one hundred and forty-nine, to the performance of their duties, unless released therefrom by the county commissioners.